Forgot to qrefresh these extra parentheses before qfinishing. Fixes these comparisons being quite indiscriminate (at one point, GrowlSafari even tried to inject into Accessorizer).
5 // Created by Peter Hosey on 2009-06-14.
6 // Copyright 2009 Peter Hosey. All rights reserved.
9 #import "GrowlSafariLoader.h"
11 #import "InterestingBundleIdentifiers.h"
13 @interface GrowlSafariLoader ()
15 - (void) workspaceDidLaunchApplication:(NSNotification *)notification;
19 @implementation GrowlSafariLoader
22 if((self = [super init])) {
23 workspace = [[NSWorkspace sharedWorkspace] retain];
24 NSNotificationCenter *nc = [workspace notificationCenter];
25 NSLog(@"Adding %@ as an observer on %@ for %@ with object %@", self, nc, NSWorkspaceDidLaunchApplicationNotification, workspace);
27 selector:@selector(workspaceDidLaunchApplication:)
28 name:NSWorkspaceDidLaunchApplicationNotification
35 NSNotificationCenter *nc = [workspace notificationCenter];
36 [nc removeObserver:self
37 name:NSWorkspaceDidLaunchApplicationNotification
44 - (void) applicationDidFinishLaunching:(NSNotification *)notification {
45 //Scan for running Safari instances, and send ourselves messages as if NSWorkspace had posted notifications about them.
46 NSEnumerator *appsEnum = [[workspace launchedApplications] objectEnumerator];
47 NSDictionary *appDict;
48 while ((appDict = [appsEnum nextObject])) {
49 NSNotification *notification = [NSNotification notificationWithName:NSWorkspaceDidLaunchApplicationNotification object:workspace userInfo:appDict];
50 [self workspaceDidLaunchApplication:notification];
54 - (BOOL) isOnSnowLeopardOrLater {
57 SInt32 majorOSVersion = 10, minorOSVersion = 0;
58 err = Gestalt(gestaltSystemVersionMajor, &majorOSVersion);
59 NSAssert2(err == noErr, @"Could not get operating-system major version number: %li/%s", (long)err, GetMacOSStatusCommentString(err));
60 err = Gestalt(gestaltSystemVersionMinor, &minorOSVersion);
61 NSAssert2(err == noErr, @"Could not get operating-system minor version number: %li/%s", (long)err, GetMacOSStatusCommentString(err));
63 return (majorOSVersion == 10 && minorOSVersion >= 6) || (majorOSVersion > 10);
66 - (void) workspaceDidLaunchApplication:(NSNotification *)notification {
67 NSDictionary *launchedProcessInfo = [notification userInfo];
68 NSString *bundleID = [launchedProcessInfo objectForKey:@"NSApplicationBundleIdentifier"];
69 if (bundleID && (([bundleID caseInsensitiveCompare:SAFARI_BUNDLE_ID] == NSOrderedSame) || ([bundleID caseInsensitiveCompare:WEBKIT_LAUNCHER_BUNDLE_ID] == NSOrderedSame))) {
70 NSString *bundlePath = [[NSBundle bundleForClass:[self class]] pathForResource:@"GrowlSafari" ofType:@"bundle"];
72 NSNumber *PIDNum = [launchedProcessInfo objectForKey:@"NSApplicationProcessIdentifier"];
73 pid_t pid = [PIDNum intValue];
75 NSArray *arguments = [NSArray arrayWithObjects:
79 #elif defined(__x86_64__)
80 //Safari did not exist in x86_64 before Snow Leopard, so, on older versions of Mac OS X, run the helper as i386.
81 [self isOnSnowLeopardOrLater] ? @"x86_64" : @"i386",
82 #elif defined(__ppc__)
85 #error Unsupported architecture
87 [[NSBundle bundleForClass:[self class]] pathForAuxiliaryExecutable:@"GrowlSafariHelper"],
88 [NSString stringWithFormat:@"%d", pid],
90 NSTask *task = [[[NSTask alloc] init] autorelease];
91 [task setLaunchPath:@"/usr/bin/arch"];
92 [task setArguments:arguments];