UNPKG

5.42 kBMarkdownView Raw
1# node-notifier [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][depstat-image]][depstat-url]
2
3A node module for sending notification using node. Uses terminal-notifier on mac,
4notify-send for Linux and growl for others.
5
6For mac this is a wrapper for the
7[terminal-notifier](https://github.com/alloy/terminal-notifier) application by
8[Eloy Durán](https://github.com/alloy).
9
10## Requirements
11- Mac OS X (>= 10.8)
12- Linux with the notify-send module
13- Or Growl on Windows
14
15If using Linux, `notify-send` must be installed on your system.
16However, [terminal-notifier](https://github.com/alloy/terminal-notifier), comes
17bundled in the module. So on Mac, not additional installations is necessary.
18
19If using Windows/Growl, `growl` must be installed. For windows see
20[Growl for Windows](http://www.growlforwindows.com/gfw/). You can also use
21growl on mac, but you need to specify this manually (see API).
22
23By default Notification Center will be used on Mac, notify-send will be used
24on Linux, and Growl will be used if neither mac or linux.
25
26## Install
27```
28$ npm install node-notifier
29```
30
31## Standard Usage
32```javascript
33var Notification = require('node-notifier');
34
35var notifier = new Notification();
36notifier.notify({
37 message: 'Hello World'
38});
39```
40
41`Notification` also has specifications for all types of notifications, to be used
42manually.
43
44Example:
45```javascript
46var nn = require('node-notifier');
47
48new nn.NotificationCenter().notify();
49new nn.NotifySend().notify();
50new nn.Growl().notify(options);
51```
52
53
54## Usage NotificationCenter
55
56Same usage and parameter setup as [terminal-notifier](https://github.com/alloy/terminal-notifier).
57
58---
59
60### Note: Output parsing from Notification Center is deprecated as of `3.0.0`.
61
62**Parsing of output given by terminal-notifier is removed as of node-notifier `3.0.0`.**
63You can still use both `remove` and `list` but the output given will not be parsed into a object.
64
65---
66
67
68### Example
69
70Where [terminal-notifier](https://github.com/alloy/terminal-notifier) say to use the ```-message``` option, you can do this in node-notifier
71
72```javascript
73var Notification = require('node-notifier');
74
75var notifier = new Notification();
76notifier.notify({
77 message: 'Hello World'
78});
79```
80
81You can specify the second argument as a callback for getting ```error``` and ```response```.
82
83```javascript
84var Notification = require('node-notifier');
85
86var notifier = new Notification();
87notifier.notify({
88 title: 'My application',
89 message: 'New notification'
90}, function(error, response) {
91 console.log(response);
92});
93```
94
95As of version `3.0.0`, you can also specify image used as icon or content image.
96
97
98```javascript
99
100notifier.notify({
101 "title": "Phil Coulson",
102 "subtitle": "Agent of S.H.I.E.L.D.",
103 "message": "If I come out, will you shoot me? 'Cause then I won't come out.",
104 "sound": "Funk", // case sensitive
105 "contentImage": __dirname + "/coulson.jpg",
106 "open": "file://" + __dirname + "/coulson.jpg"
107});
108
109```
110
111The response will be given as an object. E.g., when running ```notifier.notify({list: "ALL"})```, this could be the response:
112**Note: Deprecated as of version `3.0.0`.**
113
114```
115{ response:
116 [ { GroupID: null,
117 Title: 'Terminal',
118 Subtitle: null,
119 Message: 'Another message',
120 'Delivered At': Wed Dec 12 2012 15:23:38 GMT+0100 (CET) },
121 { GroupID: null,
122 Title: 'Terminal',
123 Subtitle: null,
124 Message: 'Another message',
125 'Delivered At': Wed Dec 12 2012 15:23:31 GMT+0100 (CET) },
126 { GroupID: 2,
127 Title: 'Terminal',
128 Subtitle: null,
129 Message: 'Testing',
130 'Delivered At': Wed Dec 12 2012 15:22:41 GMT+0100 (CET) },
131 { GroupID: 1,
132 Title: 'Terminal',
133 Subtitle: null,
134 Message: 'Testing',
135 'Delivered At': Wed Dec 12 2012 15:22:29 GMT+0100 (CET) } ],
136 type: 'list' }
137
138```
139
140There are three different types:
141
142- ```deliviered``` when a message is delivered.
143- ```removed``` when all or one message is removed. If all messages are removed, the response property will have several elements.
144- ```list``` when a list is presented. Even when doing ```list: 1```.
145
146
147
148## Usage NotifySend
149
150```javascript
151var Notification = require('node-notifier');
152
153var notifier = new Notification();
154notifier.notify({
155 title: 'Foo',
156 message: 'Hello World'
157 // .. and other notify-send flags
158});
159```
160
161## Usage Growl
162
163```javascript
164var Notification = require('node-notifier');
165
166var notifier = new Notification({
167 // Options as passed to Growler
168});
169notifier.notify({
170 title: 'Foo',
171 message: 'Hello World'
172 // and other growl options like sticky etc.
173});
174```
175
176See more information for constructor options in
177[growler](https://github.com/betamos/Node-Growler/).
178
179## Module TODO
180
1811. Add tests for growl
182
183
184## Changelog
185
186### `v3.0.0`
1871. Updates terminal-notifier to version 1.6.0; adding support for appIcon and contentImage
1882. Removes parsing of output sent from notifier (Notification Center)
189
190## License
191
192[MIT License](http://en.wikipedia.org/wiki/MIT_License)
193
194[npm-url]: https://npmjs.org/package/node-notifier
195[npm-image]: https://badge.fury.io/js/node-notifier.png
196
197[travis-url]: http://travis-ci.org/mikaelbr/node-notifier
198[travis-image]: https://secure.travis-ci.org/mikaelbr/node-notifier.png?branch=master
199
200[depstat-url]: https://david-dm.org/mikaelbr/node-notifier
201[depstat-image]: https://david-dm.org/mikaelbr/node-notifier.png
\No newline at end of file