Skip to content

Commit

Permalink
Exit early if the current user has no running NotificationCenter.
Browse files Browse the repository at this point in the history
  • Loading branch information
alloy committed Aug 24, 2013
1 parent 3ea6ddc commit 04e3148
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Terminal Notifier/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#import <ScriptingBridge/ScriptingBridge.h>
#import <objc/runtime.h>

NSString * const TerminalNotifierBundleID = @"nl.superalloy.oss.terminal-notifier";
NSString * const NotificationCenterUIBundleID = @"com.apple.notificationcenterui";

NSString *_fakeBundleIdentifier = nil;

Expand All @@ -12,7 +14,7 @@ @implementation NSBundle (FakeBundleIdentifier)
- (NSString *)__bundleIdentifier;
{
if (self == [NSBundle mainBundle]) {
return _fakeBundleIdentifier ? _fakeBundleIdentifier : @"nl.superalloy.oss.terminal-notifier";
return _fakeBundleIdentifier ? _fakeBundleIdentifier : TerminalNotifierBundleID;
} else {
return [self __bundleIdentifier];
}
Expand Down Expand Up @@ -97,6 +99,12 @@ - (void)applicationDidFinishLaunching:(NSNotification *)notification;
exit(0);
}

NSArray *runningProcesses = [[[NSWorkspace sharedWorkspace] runningApplications] valueForKey:@"bundleIdentifier"];
if ([runningProcesses indexOfObject:NotificationCenterUIBundleID] == NSNotFound) {
NSLog(@"[!] Unable to post a notification for the current user (%@), as it has no running NotificationCenter instance.", NSUserName());
exit(1);
}

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

NSString *subtitle = defaults[@"subtitle"];
Expand Down

0 comments on commit 04e3148

Please sign in to comment.