Skip to content

Commit

Permalink
Add ignoreDnD flag
Browse files Browse the repository at this point in the history
  • Loading branch information
julienXX committed Oct 29, 2017
1 parent ce60004 commit 783b980
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions Terminal Notifier/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ - (void)printHelpBanner;
" -contentImage URL The URL of a image to display attached to the notification (Mavericks+ only)\n" \
" -open URL The URL of a resource to open when the user clicks the notification.\n" \
" -execute COMMAND A shell command to perform when the user clicks the notification.\n" \
" -ignoreDnD Send notification even if Do Not Disturb is enabled.\n" \
"\n" \
"When the user activates a notification, the results are logged to the system logs.\n" \
"Use Console.app to view these logs.\n" \
Expand Down Expand Up @@ -205,19 +206,19 @@ - (void)applicationDidFinishLaunching:(NSNotification *)notification;
if (defaults[@"execute"]) options[@"command"] = defaults[@"execute"];
if (defaults[@"appIcon"]) options[@"appIcon"] = defaults[@"appIcon"];
if (defaults[@"contentImage"]) options[@"contentImage"] = defaults[@"contentImage"];

if (defaults[@"open"]) {
/*
* it may be better to use stringByAddingPercentEncodingWithAllowedCharacters instead of stringByAddingPercentEscapesUsingEncoding,
* but stringByAddingPercentEncodingWithAllowedCharacters is only available on OS X 10.9 or higher.
*/
NSString *encodedURL = [defaults[@"open"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:defaults[@"open"]];
NSString *fragment = [url fragment];
if (fragment) {
options[@"open"] = [self decodeFragmentInURL:encodedURL fragment:fragment];
} else {
options[@"open"] = encodedURL;
}
NSURL *url = [NSURL URLWithString:defaults[@"open"]];
if ((url && url.scheme && url.host) || [url isFileURL]) {
options[@"open"] = defaults[@"open"];
}else{
NSLog(@"'%@' is not a valid URI.", defaults[@"open"]);
exit(1);
}
}

if([[[NSProcessInfo processInfo] arguments] containsObject:@"-ignoreDnD"] == true) {
options[@"ignoreDnD"] = @YES;
}

[self deliverNotificationWithTitle:defaults[@"title"] ?: @"Terminal"
Expand Down Expand Up @@ -284,6 +285,10 @@ - (void)deliverNotificationWithTitle:(NSString *)title
if (sound != nil) {
userNotification.soundName = [sound isEqualToString: @"default"] ? NSUserNotificationDefaultSoundName : sound ;
}

if(options[@"ignoreDnD"]){
[userNotification setValue:@YES forKey:@"_ignoresDoNotDisturb"];
}

NSUserNotificationCenter *center = [NSUserNotificationCenter defaultUserNotificationCenter];
center.delegate = self;
Expand Down

0 comments on commit 783b980

Please sign in to comment.