Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add Notification Center Support on 10.8 #22

Merged
merged 4 commits into from

2 participants

@drudge

Closes #20. This uses node-ffi, I'm sure there is a better way. What do you think?

@tj
Owner
tj commented

hmm what do we need node-ffi for? the sync exec?

@drudge
@tj
Owner
tj commented

howcome we can't just use the async exec()? fire-and-forget style or optional callback like before

@drudge

Updated with your which command from nshell to remove the dependency on execSync and node-ffi.

@tj tj merged commit 1b78465 into tj:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 6, 2012
  1. @drudge
  2. @drudge

    Update Readme.md

    drudge authored
  3. @drudge

    Update Readme.md

    drudge authored
  4. @drudge

    Remove existsSync dependency

    drudge authored
This page is out of date. Refresh to see the latest.
Showing with 73 additions and 28 deletions.
  1. +4 −2 Readme.md
  2. +66 −24 lib/growl.js
  3. +3 −2 package.json
View
6 Readme.md
@@ -8,8 +8,10 @@ Growl support for Nodejs. This is essentially a port of my [Ruby Growl Library](
### Mac OS X (Darwin):
- Install [growlnotify(1)](http://growl.info/extras.php#growlnotify).
-
+ Install [growlnotify(1)](http://growl.info/extras.php#growlnotify). On OS X 10.8, Notification Center is supported using [terminal-notifier](https://github.com/alloy/terminal-notifier). To install:
+
+ $ sudo gem install terminal-notifier
+
Install [npm](http://npmjs.org/) and run:
$ npm install growl
View
90 lib/growl.js
@@ -5,33 +5,58 @@
*/
var exec = require('child_process').exec
+ , exists = require('fs').existsSync
, path = require('path')
, os = require('os')
, cmd;
+function which(name) {
+ var paths = process.env.PATH.split(':');
+ var loc;
+
+ for (var i = 0, len = paths.length; i < len; ++i) {
+ loc = path.join(paths[i], name);
+ if (exists(loc)) return loc;
+ }
+}
+
switch(os.type()) {
case 'Darwin':
- cmd = {
- type: "Darwin"
- , pkg: "growlnotify"
- , msg: '-m'
- , sticky: '--sticky'
- , priority: {
- cmd: '--priority'
- , range: [
- -2
- , -1
- , 0
- , 1
- , 2
- , "Very Low"
- , "Moderate"
- , "Normal"
- , "High"
- , "Emergency"
- ]
- }
- };
+ if (which('terminal-notifier')) {
+ cmd = {
+ type: "Darwin-NotificationCenter"
+ , pkg: "terminal-notifier"
+ , msg: '-message'
+ , title: '-title'
+ , subtitle: '-subtitle'
+ , priority: {
+ cmd: '-execute'
+ , range: []
+ }
+ };
+ } else {
+ cmd = {
+ type: "Darwin-Growl"
+ , pkg: "growlnotify"
+ , msg: '-m'
+ , sticky: '--sticky'
+ , priority: {
+ cmd: '--priority'
+ , range: [
+ -2
+ , -1
+ , 0
+ , 1
+ , 2
+ , "Very Low"
+ , "Moderate"
+ , "Normal"
+ , "High"
+ , "Emergency"
+ ]
+ }
+ };
+ }
break;
case 'Linux':
cmd = {
@@ -127,7 +152,7 @@ function growl(msg, options, fn) {
// image
if (image = options.image) {
switch(cmd.type) {
- case 'Darwin':
+ case 'Darwin-Growl':
var flag, ext = path.extname(image).substr(1)
flag = flag || ext == 'icns' && 'iconpath'
flag = flag || /^[A-Z]/.test(image) && 'appIcon'
@@ -158,12 +183,29 @@ function growl(msg, options, fn) {
}
// name
- if (options.name && cmd.type === "Darwin") {
+ if (options.name && cmd.type === "Darwin-Growl") {
args.push('--name', options.name);
}
switch(cmd.type) {
- case 'Darwin':
+ case 'Darwin-Growl':
+ args.push(cmd.msg);
+ args.push('"' + msg + '"');
+ if (options.title) args.push('"' + options.title + '"');
+ break;
+ case 'Darwin-NotificationCenter':
+ args.push(cmd.msg);
+ args.push('"' + msg + '"');
+ if (options.title) {
+ args.push(cmd.title);
+ args.push('"' + options.title + '"');
+ }
+ if (options.subtitle) {
+ args.push(cmd.subtitle);
+ args.push('"' + options.subtitle + '"');
+ }
+ break;
+ case 'Darwin-Growl':
args.push(cmd.msg);
args.push('"' + msg + '"');
if (options.title) args.push('"' + options.title + '"');
View
5 package.json
@@ -1,6 +1,7 @@
-{ "name": "growl",
+{
+ "name": "growl",
"version": "1.5.1",
"description": "Growl unobtrusive notifications",
"author": "TJ Holowaychuk <tj@vision-media.ca>",
"main": "./lib/growl.js"
-}
+}
Something went wrong with that request. Please try again.