Skip to content

Commit

Permalink
Support 3 last macOS versions so 10.10 for now minimum
Browse files Browse the repository at this point in the history
  • Loading branch information
julienXX committed Oct 29, 2017
1 parent ce748fa commit 846ca1a
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 60 deletions.
12 changes: 1 addition & 11 deletions README.markdown
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
# terminal-notifier

terminal-notifier is a command-line tool to send macOS User Notifications,
which are available on macOS 10.8 and higher.
which are available on macOS 10.10 and higher.


## Caveats

* On macOS 10.8, the `-appIcon` and `-contentImage` options do nothing.
This is because Notification Center on 10.8 _always_ uses the application’s own icon.

You can do one of the following to work around this limitation on 10.8:
- Use the `-sender` option to “fake it” (see below)
- Include a build of terminal-notifier with your icon **and a different bundle identifier**.
(If you don’t change the bundle identifier, launch services uses a cached version of the icon.)

However, you _can_ use unicode symbols and emojis! See the examples.

* It is currently packaged as an application bundle, because `NSUserNotification`
does not work from a ‘Foundation tool’. [radar://11956694](radar://11956694)

Expand Down
2 changes: 1 addition & 1 deletion Ruby/README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

A simple Ruby wrapper around the [`terminal-notifier`][HOMEPAGE] command-line
tool, which allows you to send User Notifications to the Notification Center on
Mac OS X 10.8, or higher.
macOS 10.10, or higher.


## Installation
Expand Down
14 changes: 7 additions & 7 deletions Ruby/lib/terminal-notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ module TerminalNotifier
BIN_PATH = File.expand_path('../../vendor/terminal-notifier/terminal-notifier.app/Contents/MacOS/terminal-notifier', __FILE__)

class UnsupportedPlatformError < StandardError; end
# Returns wether or not the current platform is Mac OS X 10.8, or higher.
# Returns wether or not the current platform is macOS 10.10, or higher.
def self.available?
@available ||= (/darwin|mac os/ =~ RbConfig::CONFIG['host_os']) && Gem::Version.new(version) > Gem::Version.new('10.8')
@available ||= (/darwin|mac os/ =~ RbConfig::CONFIG['host_os']) && Gem::Version.new(version) > Gem::Version.new('10.10')
end

def self.version
Expand All @@ -26,19 +26,19 @@ def self.execute(verbose, options)
end
result
else
STDERR.print "terminal-notifier is only supported on Mac OS X 10.8, or higher."
STDERR.print "terminal-notifier is only supported on macOS 10.10, or higher."
end
end

# Cleans up the result of a notification, making it easier to work it
#
#
# The result of a notification is downcased, then groups of 1 or more
# non-word characters are replaced with an underscore, before being
# symbolised.
# symbolised.
#
# If the reply option was given, then instead of going through the
# If the reply option was given, then instead of going through the
# above process, the result is returned with no changes as a string.
#
#
# If the always_string param is set to true, a the result is returned
# with no changes as a string, like above.
#
Expand Down
2 changes: 1 addition & 1 deletion Ruby/terminal-notifier.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ version = File.read(plist).match(%r{<string>(\d+\.\d+\.\d+)</string>})[1]
Gem::Specification.new do |gem|
gem.name = "terminal-notifier"
gem.version = version
gem.summary = 'Send User Notifications on Mac OS X 10.8 or higher.'
gem.summary = 'Send User Notifications on macOS 10.10 or higher.'
gem.authors = ["Eloy Duran", "Julien Blanchard"]
gem.email = ["eloy.de.enige@gmail.com", "julien@sideburns.eu"]
gem.homepage = 'https://github.com/julienXX/terminal-notifier'
Expand Down
55 changes: 16 additions & 39 deletions Terminal Notifier/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
#import <ScriptingBridge/ScriptingBridge.h>
#import <objc/runtime.h>

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

// Set OS Params
#define NSAppKitVersionNumber10_8 1187
#define NSAppKitVersionNumber10_9 1265
#define NSAppKitVersionNumber10_10 1343

#define contains(str1, str2) ([str1 rangeOfString: str2 ].location != NSNotFound)

Expand Down Expand Up @@ -40,18 +39,6 @@ - (NSString *)__bundleIdentifier;
return NO;
}

static BOOL
isMavericks()
{
if (floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_8) {
/* On a 10.8 - 10.8.x system */
return NO;
} else {
/* 10.9 or later system */
return YES;
}
}

@implementation NSUserDefaults (SubscriptAndUnescape)
- (id)objectForKeyedSubscript:(id)key;
{
Expand All @@ -72,14 +59,7 @@ +(void)initializeUserDefaults

// initialize the dictionary with default values depending on OS level
NSDictionary *appDefaults;

if (isMavericks()) {
//10.9
appDefaults = @{@"sender": @"com.apple.Terminal"};
} else {
//10.8
appDefaults = @{@"": @"message"};
}
appDefaults = @{@"sender": @"com.apple.Terminal"};

// and set them appropriately
[defaults registerDefaults:appDefaults];
Expand All @@ -89,7 +69,7 @@ - (void)printHelpBanner;
{
const char *appName = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleExecutable"] UTF8String];
const char *appVersion = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"] UTF8String];
printf("%s (%s) is a command-line tool to send OS X User Notifications.\n" \
printf("%s (%s) is a command-line tool to send macOS User Notifications.\n" \
"\n" \
"Usage: %s -[message|list|remove] [VALUE|ID|ID] [options]\n" \
"\n" \
Expand Down Expand Up @@ -147,7 +127,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)notification;
[self printHelpBanner];
exit(0);
}

if ([[[NSProcessInfo processInfo] arguments] indexOfObject:@"-version"] != NSNotFound) {
[self printVersion];
exit(0);
Expand Down Expand Up @@ -208,7 +188,7 @@ - (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"]) {
NSURL *url = [NSURL URLWithString:defaults[@"open"]];
if ((url && url.scheme && url.host) || [url isFileURL]) {
Expand All @@ -218,7 +198,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)notification;
exit(1);
}
}

if([[[NSProcessInfo processInfo] arguments] containsObject:@"-ignoreDnD"] == true) {
options[@"ignoreDnD"] = @YES;
}
Expand Down Expand Up @@ -271,23 +251,20 @@ - (void)deliverNotificationWithTitle:(NSString *)title
userNotification.informativeText = message;
userNotification.userInfo = options;

if(isMavericks()){
// Mavericks options
if(options[@"appIcon"]){
// replacement app icon
[userNotification setValue:[self getImageFromURL:options[@"appIcon"]] forKey:@"_identityImage"];
[userNotification setValue:@(false) forKey:@"_identityImageHasBorder"];
}
if(options[@"contentImage"]){
// content image
userNotification.contentImage = [self getImageFromURL:options[@"contentImage"]];
}
if(options[@"appIcon"]){
// replacement app icon
[userNotification setValue:[self getImageFromURL:options[@"appIcon"]] forKey:@"_identityImage"];
[userNotification setValue:@(false) forKey:@"_identityImageHasBorder"];
}
if(options[@"contentImage"]){
// content image
userNotification.contentImage = [self getImageFromURL:options[@"contentImage"]];
}

if (sound != nil) {
userNotification.soundName = [sound isEqualToString: @"default"] ? NSUserNotificationDefaultSoundName : sound ;
}

if(options[@"ignoreDnD"]){
[userNotification setValue:@YES forKey:@"_ignoresDoNotDisturb"];
}
Expand Down
2 changes: 1 addition & 1 deletion Terminal Notifier/Terminal Notifier-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<key>CFBundleIconFile</key>
<string>Terminal</string>
<key>CFBundleIdentifier</key>
<string>nl.superalloy.oss.${PRODUCT_NAME:rfc1034identifier}</string>
<string>fr.julienxx.oss.${PRODUCT_NAME:rfc1034identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down

0 comments on commit 846ca1a

Please sign in to comment.