Begin main content

Filtering Growl notifications

Now that I work full time on my Mac I have Skype, Notify and any number of other apps telling me stuff via Growl. One of the great things about having everything centralised through a single notification mechanism is that you can easily choose what notifications you want to see.

Growl already has a great way to choose notifications by turning Apps on or off and notification types as registered by the Apps. But it doesn't have any way to filter based on the content of the notification—e.g. if I want to see when some Skype users log on but not others.

So since Growl is open source I took matters into my own hands. I don't have a UI yet, and haven't forked the repository, but for now here's a quick patch.

The UI is you use Apple's Plist editor to add an array with key "GrowlIgnorePredicates" to com.Growl.GrowlHelperApp.plist in your Library/Preferences directory :) Here are the keys, see NSPredicate docs for predicate string syntax. If you have no idea what I just said you'll have to wait for the UI I'm afraid!

  • ApplicationName
  • NotificationTitle
  • NotificationDescription
  • And here is the patch:

    diff -r 9f9a8561261a Core/Source/GrowlApplicationController.m
    --- a/Core/Source/GrowlApplicationController.m	Sun Aug 01 10:35:51 2010 -0400
    +++ b/Core/Source/GrowlApplicationController.m	Wed Aug 04 13:18:37 2010 +1000
    @@ -592,6 +592,21 @@
     		[pool release];
     		return GrowlNotificationResultDisabled;
    +    GrowlPreferencesController *preferences = [GrowlPreferencesController sharedController];
    +    // Mark Aufflick hack - needs UI    
    +    NSArray *ignorePredicates = [preferences objectForKey:GrowlIgnorePredicates];
    +    if ([ignorePredicates isKindOfClass:[NSArray class]]) {
    +        for (NSString *predString in ignorePredicates) {
    +            NSPredicate *p = [NSPredicate predicateWithFormat:predString];
    +            if ([p evaluateWithObject:dict]) {
    +                NSLog(@"ignoring notification due to predicate: %@", p);
    +                return GrowlNotificationResultDisabled;
    +            }
    +        }
    +    }
     	NSMutableDictionary *aDict = [dict mutableCopy];
    @@ -642,8 +657,6 @@
     		value = [NSNumber numberWithInt:priority];
     	[aDict setObject:value forKey:GROWL_NOTIFICATION_PRIORITY];
    -	GrowlPreferencesController *preferences = [GrowlPreferencesController sharedController];
     	// Retrieve and set the sticky bit of the notification
     	int sticky = [notification sticky];
     	if (sticky >= 0)
    diff -r 9f9a8561261a Core/Source/GrowlPreferencesController.h
    --- a/Core/Source/GrowlPreferencesController.h	Sun Aug 01 10:35:51 2010 -0400
    +++ b/Core/Source/GrowlPreferencesController.h	Wed Aug 04 13:18:37 2010 +1000
    @@ -39,6 +39,7 @@
     #define LastKnownVersionKey			XSTR("LastKnownVersion")
     #define GrowlStickyWhenAwayKey		XSTR("StickyWhenAway")
     #define GrowlStickyIdleThresholdKey	XSTR("IdleThreshold")
    +#define GrowlIgnorePredicates       XSTR("GrowlIgnorePredicates")
     CFTypeRef GrowlPreferencesController_objectForKey(CFTypeRef key);
     CFIndex   GrowlPreferencesController_integerForKey(CFTypeRef key);

11:47 PM, 03 Aug 2010 by Mark Aufflick Permalink

Add comment