terminal-notifier 1.5.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. checksums.yaml +7 -0
  2. data/lib/terminal-notifier.rb +1 -1
  3. data/vendor/terminal-notifier/README.markdown +47 -7
  4. data/vendor/terminal-notifier/Ruby/Gemfile +2 -0
  5. data/vendor/terminal-notifier/Ruby/Gemfile.lock +23 -0
  6. data/vendor/terminal-notifier/Ruby/LICENSE +23 -0
  7. data/vendor/terminal-notifier/Ruby/README.markdown +48 -0
  8. data/vendor/terminal-notifier/Ruby/Rakefile +48 -0
  9. data/vendor/terminal-notifier/Ruby/bin/terminal-notifier +13 -0
  10. data/vendor/terminal-notifier/Ruby/lib/terminal-notifier.rb +87 -0
  11. data/vendor/terminal-notifier/Ruby/spec/terminal-notifier_spec.rb +72 -0
  12. data/vendor/terminal-notifier/Ruby/terminal-notifier.gemspec +26 -0
  13. data/vendor/terminal-notifier/Terminal Notifier/AppDelegate.h +4 -0
  14. data/vendor/terminal-notifier/Terminal Notifier/AppDelegate.m +364 -0
  15. data/vendor/terminal-notifier/Terminal Notifier/Terminal Notifier-Info.plist +36 -0
  16. data/vendor/terminal-notifier/Terminal Notifier/Terminal Notifier-Prefix.pch +7 -0
  17. data/vendor/terminal-notifier/Terminal Notifier/en.lproj/Credits.rtf +29 -0
  18. data/vendor/terminal-notifier/Terminal Notifier/en.lproj/InfoPlist.strings +2 -0
  19. data/vendor/terminal-notifier/Terminal Notifier/en.lproj/MainMenu.xib +3191 -0
  20. data/vendor/terminal-notifier/Terminal Notifier/main.m +6 -0
  21. data/vendor/terminal-notifier/Terminal Notifier.xcodeproj/project.pbxproj +311 -0
  22. data/vendor/terminal-notifier/Terminal Notifier.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  23. data/vendor/terminal-notifier/Terminal Notifier.xcodeproj/xcshareddata/xcschemes/Terminal Notifier.xcscheme +140 -0
  24. data/vendor/terminal-notifier/Terminal.icns +0 -0
  25. data/vendor/terminal-notifier/terminal-notifier.app/Contents/Info.plist +7 -7
  26. data/vendor/terminal-notifier/terminal-notifier.app/Contents/MacOS/terminal-notifier +0 -0
  27. data/vendor/terminal-notifier/terminal-notifier.app/Contents/Resources/en.lproj/MainMenu.nib +0 -0
  28. metadata +81 -78
@@ -0,0 +1,364 @@
1
+ #import "AppDelegate.h"
2
+ #import <ScriptingBridge/ScriptingBridge.h>
3
+ #import <objc/runtime.h>
4
+
5
+ NSString * const TerminalNotifierBundleID = @"nl.superalloy.oss.terminal-notifier";
6
+ NSString * const NotificationCenterUIBundleID = @"com.apple.notificationcenterui";
7
+
8
+ // Set OS Params
9
+ #define NSAppKitVersionNumber10_8 1187
10
+ #define NSAppKitVersionNumber10_9 1265
11
+
12
+ #define contains(str1, str2) ([str1 rangeOfString: str2 ].location != NSNotFound)
13
+
14
+ NSString *_fakeBundleIdentifier = nil;
15
+
16
+ @implementation NSBundle (FakeBundleIdentifier)
17
+
18
+ // Overriding bundleIdentifier works, but overriding NSUserNotificationAlertStyle does not work.
19
+
20
+ - (NSString *)__bundleIdentifier;
21
+ {
22
+ if (self == [NSBundle mainBundle]) {
23
+ return _fakeBundleIdentifier ? _fakeBundleIdentifier : TerminalNotifierBundleID;
24
+ } else {
25
+ return [self __bundleIdentifier];
26
+ }
27
+ }
28
+
29
+ @end
30
+
31
+ static BOOL
32
+ InstallFakeBundleIdentifierHook()
33
+ {
34
+ Class class = objc_getClass("NSBundle");
35
+ if (class) {
36
+ method_exchangeImplementations(class_getInstanceMethod(class, @selector(bundleIdentifier)),
37
+ class_getInstanceMethod(class, @selector(__bundleIdentifier)));
38
+ return YES;
39
+ }
40
+ return NO;
41
+ }
42
+
43
+ static BOOL
44
+ isMavericks()
45
+ {
46
+ if (floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_8) {
47
+ /* On a 10.8 - 10.8.x system */
48
+ return NO;
49
+ } else {
50
+ /* 10.9 or later system */
51
+ return YES;
52
+ }
53
+ }
54
+
55
+ @implementation NSUserDefaults (SubscriptAndUnescape)
56
+ - (id)objectForKeyedSubscript:(id)key;
57
+ {
58
+ id obj = [self objectForKey:key];
59
+ if ([obj isKindOfClass:[NSString class]] && [(NSString *)obj hasPrefix:@"\\"]) {
60
+ obj = [(NSString *)obj substringFromIndex:1];
61
+ }
62
+ return obj;
63
+ }
64
+ @end
65
+
66
+
67
+ @implementation AppDelegate
68
+
69
+ +(void)initializeUserDefaults
70
+ {
71
+ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
72
+
73
+ // initialize the dictionary with default values depending on OS level
74
+ NSDictionary *appDefaults;
75
+
76
+ if (isMavericks()) {
77
+ //10.9
78
+ appDefaults = @{@"sender": @"com.apple.Terminal"};
79
+ } else {
80
+ //10.8
81
+ appDefaults = @{@"": @"message"};
82
+ }
83
+
84
+ // and set them appropriately
85
+ [defaults registerDefaults:appDefaults];
86
+ }
87
+
88
+ - (void)printHelpBanner;
89
+ {
90
+ const char *appName = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleExecutable"] UTF8String];
91
+ const char *appVersion = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"] UTF8String];
92
+ printf("%s (%s) is a command-line tool to send OS X User Notifications.\n" \
93
+ "\n" \
94
+ "Usage: %s -[message|list|remove] [VALUE|ID|ID] [options]\n" \
95
+ "\n" \
96
+ " Either of these is required (unless message data is piped to the tool):\n" \
97
+ "\n" \
98
+ " -help Display this help banner.\n" \
99
+ " -message VALUE The notification message.\n" \
100
+ " -remove ID Removes a notification with the specified ‘group’ ID.\n" \
101
+ " -list ID If the specified ‘group’ ID exists show when it was delivered,\n" \
102
+ " or use ‘ALL’ as ID to see all notifications.\n" \
103
+ " The output is a tab-separated list.\n"
104
+ "\n" \
105
+ " Optional:\n" \
106
+ "\n" \
107
+ " -title VALUE The notification title. Defaults to ‘Terminal’.\n" \
108
+ " -subtitle VALUE The notification subtitle.\n" \
109
+ " -sound NAME The name of a sound to play when the notification appears. The names are listed\n" \
110
+ " in Sound Preferences. Use 'default' for the default notification sound.\n" \
111
+ " -group ID A string which identifies the group the notifications belong to.\n" \
112
+ " Old notifications with the same ID will be removed.\n" \
113
+ " -activate ID The bundle identifier of the application to activate when the user clicks the notification.\n" \
114
+ " -sender ID The bundle identifier of the application that should be shown as the sender, including its icon.\n" \
115
+ " -appIcon URL The URL of a image to display instead of the application icon (Mavericks+ only)\n" \
116
+ " -contentImage URL The URL of a image to display attached to the notification (Mavericks+ only)\n" \
117
+ " -open URL The URL of a resource to open when the user clicks the notification.\n" \
118
+ " -execute COMMAND A shell command to perform when the user clicks the notification.\n" \
119
+ "\n" \
120
+ "When the user activates a notification, the results are logged to the system logs.\n" \
121
+ "Use Console.app to view these logs.\n" \
122
+ "\n" \
123
+ "Note that in some circumstances the first character of a message has to be escaped in order to be recognized.\n" \
124
+ "An example of this is when using an open bracket, which has to be escaped like so: ‘\\[’.\n" \
125
+ "\n" \
126
+ "For more information see https://github.com/alloy/terminal-notifier.\n",
127
+ appName, appVersion, appName);
128
+ }
129
+
130
+ - (void)applicationDidFinishLaunching:(NSNotification *)notification;
131
+ {
132
+ NSUserNotification *userNotification = notification.userInfo[NSApplicationLaunchUserNotificationKey];
133
+ if (userNotification) {
134
+ [self userActivatedNotification:userNotification];
135
+
136
+ } else {
137
+ if ([[[NSProcessInfo processInfo] arguments] indexOfObject:@"-help"] != NSNotFound) {
138
+ [self printHelpBanner];
139
+ exit(0);
140
+ }
141
+
142
+ NSArray *runningProcesses = [[[NSWorkspace sharedWorkspace] runningApplications] valueForKey:@"bundleIdentifier"];
143
+ if ([runningProcesses indexOfObject:NotificationCenterUIBundleID] == NSNotFound) {
144
+ NSLog(@"[!] Unable to post a notification for the current user (%@), as it has no running NotificationCenter instance.", NSUserName());
145
+ exit(1);
146
+ }
147
+
148
+ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
149
+
150
+ NSString *subtitle = defaults[@"subtitle"];
151
+ NSString *message = defaults[@"message"];
152
+ NSString *remove = defaults[@"remove"];
153
+ NSString *list = defaults[@"list"];
154
+ NSString *sound = defaults[@"sound"];
155
+
156
+ // If there is no message and data is piped to the application, use that
157
+ // instead.
158
+ if (message == nil && !isatty(STDIN_FILENO)) {
159
+ NSData *inputData = [NSData dataWithData:[[NSFileHandle fileHandleWithStandardInput] readDataToEndOfFile]];
160
+ message = [[NSString alloc] initWithData:inputData encoding:NSUTF8StringEncoding];
161
+ }
162
+
163
+ if (message == nil && remove == nil && list == nil) {
164
+ [self printHelpBanner];
165
+ exit(1);
166
+ }
167
+
168
+ if (list) {
169
+ [self listNotificationWithGroupID:list];
170
+ exit(0);
171
+ }
172
+
173
+ // Install the fake bundle ID hook so we can fake the sender. This also
174
+ // needs to be done to be able to remove a message.
175
+ if (defaults[@"sender"]) {
176
+ @autoreleasepool {
177
+ if (InstallFakeBundleIdentifierHook()) {
178
+ _fakeBundleIdentifier = defaults[@"sender"];
179
+ }
180
+ }
181
+ }
182
+
183
+ if (remove) {
184
+ [self removeNotificationWithGroupID:remove];
185
+ if (message == nil) exit(0);
186
+ }
187
+
188
+ if (message) {
189
+ NSMutableDictionary *options = [NSMutableDictionary dictionary];
190
+ if (defaults[@"activate"]) options[@"bundleID"] = defaults[@"activate"];
191
+ if (defaults[@"group"]) options[@"groupID"] = defaults[@"group"];
192
+ if (defaults[@"execute"]) options[@"command"] = defaults[@"execute"];
193
+ if (defaults[@"open"]) options[@"open"] = [defaults[@"open"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
194
+ if (defaults[@"appIcon"]) options[@"appIcon"] = defaults[@"appIcon"];
195
+ if (defaults[@"contentImage"]) options[@"contentImage"] = defaults[@"contentImage"];
196
+
197
+ [self deliverNotificationWithTitle:defaults[@"title"] ?: @"Terminal"
198
+ subtitle:subtitle
199
+ message:message
200
+ options:options
201
+ sound:sound];
202
+ }
203
+ }
204
+ }
205
+
206
+ - (NSImage*)getImageFromURL:(NSString *) url;
207
+ {
208
+ if(!contains(url, @"file://")){ // Prefix file:// if not present
209
+ url = [NSString stringWithFormat:@"%@%@", @"file://", url];
210
+ }
211
+ NSURL *imageURL = [NSURL URLWithString:url];
212
+ return [[NSImage alloc] initWithContentsOfURL:imageURL];
213
+ }
214
+
215
+ - (void)deliverNotificationWithTitle:(NSString *)title
216
+ subtitle:(NSString *)subtitle
217
+ message:(NSString *)message
218
+ options:(NSDictionary *)options
219
+ sound:(NSString *)sound;
220
+ {
221
+ // First remove earlier notification with the same group ID.
222
+ if (options[@"groupID"]) [self removeNotificationWithGroupID:options[@"groupID"]];
223
+
224
+ NSUserNotification *userNotification = [NSUserNotification new];
225
+ userNotification.title = title;
226
+ userNotification.subtitle = subtitle;
227
+ userNotification.informativeText = message;
228
+ userNotification.userInfo = options;
229
+
230
+ if(isMavericks()){
231
+ // Mavericks options
232
+ if(options[@"appIcon"]){
233
+ // replacement app icon
234
+ [userNotification setValue:[self getImageFromURL:options[@"appIcon"]] forKey:@"_identityImage"];
235
+ [userNotification setValue:@(true) forKey:@"_identityImageHasBorder"];
236
+ }
237
+ if(options[@"contentImage"]){
238
+ // content image
239
+ userNotification.contentImage = [self getImageFromURL:options[@"contentImage"]];
240
+ }
241
+ }
242
+
243
+ if (sound != nil) {
244
+ userNotification.soundName = [sound isEqualToString: @"default"] ? NSUserNotificationDefaultSoundName : sound ;
245
+ }
246
+
247
+ NSUserNotificationCenter *center = [NSUserNotificationCenter defaultUserNotificationCenter];
248
+ center.delegate = self;
249
+ [center scheduleNotification:userNotification];
250
+ }
251
+
252
+ - (void)removeNotificationWithGroupID:(NSString *)groupID;
253
+ {
254
+ NSUserNotificationCenter *center = [NSUserNotificationCenter defaultUserNotificationCenter];
255
+ for (NSUserNotification *userNotification in center.deliveredNotifications) {
256
+ if ([@"ALL" isEqualToString:groupID] || [userNotification.userInfo[@"groupID"] isEqualToString:groupID]) {
257
+ NSString *deliveredAt = [userNotification.actualDeliveryDate description];
258
+ printf("* Removing previously sent notification, which was sent on: %s\n", [deliveredAt UTF8String]);
259
+ [center removeDeliveredNotification:userNotification];
260
+ }
261
+ }
262
+ }
263
+
264
+ - (void)listNotificationWithGroupID:(NSString *)listGroupID;
265
+ {
266
+ NSUserNotificationCenter *center = [NSUserNotificationCenter defaultUserNotificationCenter];
267
+
268
+ NSMutableArray *lines = [NSMutableArray array];
269
+ for (NSUserNotification *userNotification in center.deliveredNotifications) {
270
+ NSString *deliveredgroupID = userNotification.userInfo[@"groupID"];
271
+ NSString *title = userNotification.title;
272
+ NSString *subtitle = userNotification.subtitle;
273
+ NSString *message = userNotification.informativeText;
274
+ NSString *deliveredAt = [userNotification.actualDeliveryDate description];
275
+ if ([@"ALL" isEqualToString:listGroupID] || [deliveredgroupID isEqualToString:listGroupID]) {
276
+ [lines addObject:[NSString stringWithFormat:@"%@\t%@\t%@\t%@\t%@", deliveredgroupID, title, subtitle, message, deliveredAt]];
277
+ }
278
+ }
279
+
280
+ if (lines.count > 0) {
281
+ printf("GroupID\tTitle\tSubtitle\tMessage\tDelivered At\n");
282
+ for (NSString *line in lines) {
283
+ printf("%s\n", [line UTF8String]);
284
+ }
285
+ }
286
+ }
287
+
288
+
289
+ - (void)userActivatedNotification:(NSUserNotification *)userNotification;
290
+ {
291
+ [[NSUserNotificationCenter defaultUserNotificationCenter] removeDeliveredNotification:userNotification];
292
+
293
+ NSString *groupID = userNotification.userInfo[@"groupID"];
294
+ NSString *bundleID = userNotification.userInfo[@"bundleID"];
295
+ NSString *command = userNotification.userInfo[@"command"];
296
+ NSString *open = userNotification.userInfo[@"open"];
297
+
298
+ NSLog(@"User activated notification:");
299
+ NSLog(@" group ID: %@", groupID);
300
+ NSLog(@" title: %@", userNotification.title);
301
+ NSLog(@" subtitle: %@", userNotification.subtitle);
302
+ NSLog(@" message: %@", userNotification.informativeText);
303
+ NSLog(@"bundle ID: %@", bundleID);
304
+ NSLog(@" command: %@", command);
305
+ NSLog(@" open: %@", open);
306
+
307
+ BOOL success = YES;
308
+ if (bundleID) success &= [self activateAppWithBundleID:bundleID];
309
+ if (command) success &= [self executeShellCommand:command];
310
+ if (open) success &= [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:open]];
311
+
312
+ exit(success ? 0 : 1);
313
+ }
314
+
315
+ - (BOOL)activateAppWithBundleID:(NSString *)bundleID;
316
+ {
317
+ id app = [SBApplication applicationWithBundleIdentifier:bundleID];
318
+ if (app) {
319
+ [app activate];
320
+ return YES;
321
+
322
+ } else {
323
+ NSLog(@"Unable to find an application with the specified bundle indentifier.");
324
+ return NO;
325
+ }
326
+ }
327
+
328
+ - (BOOL)executeShellCommand:(NSString *)command;
329
+ {
330
+ NSPipe *pipe = [NSPipe pipe];
331
+ NSFileHandle *fileHandle = [pipe fileHandleForReading];
332
+
333
+ NSTask *task = [NSTask new];
334
+ task.launchPath = @"/bin/sh";
335
+ task.arguments = @[@"-c", command];
336
+ task.standardOutput = pipe;
337
+ task.standardError = pipe;
338
+ [task launch];
339
+
340
+ NSData *data = nil;
341
+ NSMutableData *accumulatedData = [NSMutableData data];
342
+ while ((data = [fileHandle availableData]) && [data length]) {
343
+ [accumulatedData appendData:data];
344
+ }
345
+
346
+ [task waitUntilExit];
347
+ NSLog(@"command output:\n%@", [[NSString alloc] initWithData:accumulatedData encoding:NSUTF8StringEncoding]);
348
+ return [task terminationStatus] == 0;
349
+ }
350
+
351
+ - (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center
352
+ shouldPresentNotification:(NSUserNotification *)userNotification;
353
+ {
354
+ return YES;
355
+ }
356
+
357
+ // Once the notification is delivered we can exit.
358
+ - (void)userNotificationCenter:(NSUserNotificationCenter *)center
359
+ didDeliverNotification:(NSUserNotification *)userNotification;
360
+ {
361
+ exit(0);
362
+ }
363
+
364
+ @end
@@ -0,0 +1,36 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>CFBundleDevelopmentRegion</key>
6
+ <string>en</string>
7
+ <key>CFBundleExecutable</key>
8
+ <string>${EXECUTABLE_NAME}</string>
9
+ <key>CFBundleIconFile</key>
10
+ <string>Terminal</string>
11
+ <key>CFBundleIdentifier</key>
12
+ <string>nl.superalloy.oss.${PRODUCT_NAME:rfc1034identifier}</string>
13
+ <key>CFBundleInfoDictionaryVersion</key>
14
+ <string>6.0</string>
15
+ <key>CFBundleName</key>
16
+ <string>${PRODUCT_NAME}</string>
17
+ <key>CFBundlePackageType</key>
18
+ <string>APPL</string>
19
+ <key>CFBundleShortVersionString</key>
20
+ <string>1.6.0</string>
21
+ <key>CFBundleSignature</key>
22
+ <string>????</string>
23
+ <key>CFBundleVersion</key>
24
+ <string>11</string>
25
+ <key>LSMinimumSystemVersion</key>
26
+ <string>${MACOSX_DEPLOYMENT_TARGET}</string>
27
+ <key>LSUIElement</key>
28
+ <true/>
29
+ <key>NSHumanReadableCopyright</key>
30
+ <string>Copyright © 2012 Eloy Durán. All rights reserved.</string>
31
+ <key>NSMainNibFile</key>
32
+ <string>MainMenu</string>
33
+ <key>NSPrincipalClass</key>
34
+ <string>NSApplication</string>
35
+ </dict>
36
+ </plist>
@@ -0,0 +1,7 @@
1
+ //
2
+ // Prefix header for all source files of the 'Terminal Notifier' target in the 'Terminal Notifier' project
3
+ //
4
+
5
+ #ifdef __OBJC__
6
+ #import <Cocoa/Cocoa.h>
7
+ #endif
@@ -0,0 +1,29 @@
1
+ {\rtf0\ansi{\fonttbl\f0\fswiss Helvetica;}
2
+ {\colortbl;\red255\green255\blue255;}
3
+ \paperw9840\paperh8400
4
+ \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural
5
+
6
+ \f0\b\fs24 \cf0 Engineering:
7
+ \b0 \
8
+ Some people\
9
+ \
10
+
11
+ \b Human Interface Design:
12
+ \b0 \
13
+ Some other people\
14
+ \
15
+
16
+ \b Testing:
17
+ \b0 \
18
+ Hopefully not nobody\
19
+ \
20
+
21
+ \b Documentation:
22
+ \b0 \
23
+ Whoever\
24
+ \
25
+
26
+ \b With special thanks to:
27
+ \b0 \
28
+ Mom\
29
+ }
@@ -0,0 +1,2 @@
1
+ /* Localized versions of Info.plist keys */
2
+