Code Monkey home page Code Monkey logo

node-osx-notifier's Introduction

node-osx-notifier

A NodeJS Server for sending notifications to OSX Mountain Lion's Notification Center.

Synopsis

OSX Mountain Lion comes packaged with a built-in notification center. For whatever reason, Apple sandboxed the notification center API to apps hosted in its App Store. The end result? A potentially useful API shackled to Apple's ecosystem.

Thankfully, Eloy Durán put together a set of sweet osx apps that allow terminal access to the sandboxed API. node-osx-notifier wraps these apps with a simple express server, exposing an HTTP interface to the closed API.

It's not perfect, and the implementor will quickly notice its limitations. However, it's a start and any pull requests are accepted and encouraged!

Installation

The following command will install the notification server. Use -g to install the server as a global binary.

[sudo] npm install [-g] node-osx-notifier

Running The Server

Running the server is easy peasy. If you installed the server globally, then starting the server is as easy as:

node-osx-notifier [port] [host]

The port and host will default to 1337 and localhost respectively.

Testing The Server

You can then test that the server is running correctly by making a request to it. The simplest request uses the querystring over HTTP GET:

curl "http://localhost:1337/info?message=test"
{
  "status": "* Notification delivered."
}

You can also use the JSON interface to POST the same content to the server:

curl -H "Content-Type: application/json" -X POST -d '{"message":"test"}' "http://localhost:1338/info"
{
  "status": "* Notification delivered."
}

The HTTP API

For starters, you want to pick from one of three notification types. The notification types are designated by the path of the server request. Each notification type changes the icon and section in the notification center:

  • info http://localhost:1337/info used for basic notifications
    • info screenshot
  • pass http://localhost:1337/pass used for showing that a job has passed
    • info screenshot
  • fail http://localhost:1337/fail used for showing that a job has failed
    • info screenshot

In addition, you will also need to pass parameters (as JSON POST-data or a querystring) that tells the server what to do for a given notification type. Since the server acts as a wrapper, these parameters match the command-line options defined by the underlying apps. For completeness, those parameters are outlined below:

At a minimum, you have to specify either the -message , the -remove option or the -list option.


-message VALUE [required]

The message body of the notification.


-title VALUE

The title of the notification. This defaults to ‘Terminal’.


-subtitle VALUE

The subtitle of the notification.


-group ID

Specifies the ‘group’ a notification belongs to. For any ‘group’ only one notification will ever be shown, replacing previously posted notifications.

A notification can be explicitely removed with the -remove option, describe below.

Examples are:

  • The sender’s name to scope the notifications by tool.
  • The sender’s process ID to scope the notifications by a unique process.
  • The current working directory to scope notifications by project.

-remove ID [required]

Removes a notification that was previously sent with the specified ‘group’ ID, if one exists. If used with the special group "ALL", all message are removed.


-list ID [required]

Lists details about the specified ‘group’ ID. If used with the special group "ALL", details about all currently active messages are displayed.

The output of this command is tab-separated, which makes it easy to parse.


-activate ID

Specifies which application should be activated when the user clicks the notification.

You can find the bundle identifier of an application in its Info.plist file inside the application bundle.

Examples are:

  • com.apple.Terminal to activate Terminal.app
  • com.apple.Safari to activate Safari.app

-open URL

Specifies a resource to be opened when the user clicks the notification. This can be a web or file URL, or any custom URL scheme.


-execute COMMAND

Specifies a shell command to run when the user clicks the notification.

Licence

This project is dual licensed under the MIT license and defers to any licensing defined by the underlying apps.

Additional Support

If you're having problems with using the project, use the support forum at CodersClan.

node-osx-notifier's People

Contributors

snappedtogrid avatar

Stargazers

Cat  avatar Sheldon Rupp avatar Thomas McLeod avatar Egor Rudinsky avatar Marc Romeyn avatar Chris Braddock avatar Sergey Matyash avatar Riccardo avatar  avatar Kevin Mitchell Jr  avatar Christoph Lehmann avatar Jeffrey Carpenter avatar Angus H. avatar vincent_b avatar Tim Kendall avatar Rick Blundell avatar Eirik L. Vullum avatar Marten Bjork avatar Alexander Mistakidis avatar Hayato Mizuno avatar Ben McGinnis avatar Hamza Faran avatar Tony Li avatar Andrew M. avatar Lisovskii Vladislav avatar Seongsu Yoon avatar Drew LeSueur avatar Andrew Abramov avatar Tsubaki avatar Joseph Kim avatar Yosh avatar Stefan Liedle avatar JaePil Jung avatar Mundi Morgado avatar Marshall T. Rose avatar Dan Barrett avatar Omeed avatar  avatar  avatar Shengtuo Hu avatar Sean G avatar Guo Yu avatar GyuYong Jung avatar Jose Gascon avatar Rui Onodera avatar Nathan Leiby avatar Nikita Kovalev avatar youpy avatar Laurent M avatar Rafael Díez avatar Derek Myers avatar saighost avatar  avatar Jonathan Allard avatar Marcos Scriven avatar paolotoldo avatar patrick avatar 许诺 avatar wangshijun avatar  avatar  avatar Jesse Youngblood avatar Mathias Novas avatar Melchor Garau Madrigal avatar  avatar  avatar walterzhang avatar Brad Batt avatar Monting avatar Maxim avatar dap avatar Manuel Albarran avatar  avatar Andre Becker avatar Sean Lynch avatar  avatar Moudy avatar Giacomo Giudice avatar Nicholas Audo avatar Kendrick Von Ledet avatar Andrea Collet avatar John Rodler avatar Adam Snodgrass avatar Massimiliano Marcon avatar Iddar Olivares avatar Hugo Lopes Tavares avatar Brian Sigafoos avatar Jan avatar Sam Sulaimanov avatar Eric Gallager avatar Tomáš Horáček avatar Eugene MechanisM avatar Gosha Spark avatar Antonin Hildebrand avatar Petr Bela avatar Constantine Kim 김현진 avatar Dal Hundal avatar Brian Lalor avatar Cris Kim avatar Richard Hoffmann avatar

Watchers

Łukasz Twarogowski avatar Andy Fuchs avatar Michael Nilsson avatar mnicholls avatar  avatar 斯人 avatar Mike Preisinger avatar James Cloos avatar Caner Altinbasak avatar Krister Kari avatar jikoon kong avatar Dean Neitman avatar Michele Venturi avatar Zeus avatar Jasper Ke avatar Vladislavs Burakovs avatar Teameh avatar Rick Blundell avatar  avatar

node-osx-notifier's Issues

Changing the app title.

I can't get this to change from terminal-notifier-pass.
Can you point me in the right direction?

Why number can't be send?

var duration = 45;
function notifyMsg(title,subtitle,str){
notify({
    type: 'pass',
    title: title,
    subtitle: subtitle,
    message: str,
    group: 'taskdoer'
});

}

notifyMsg("测试","sdaf-5.66","")

ERROR:

terminal-notifier (1.5.0) is a command-line tool to send OS X User Notifications.

Usage: terminal-notifier -[message|list|remove] [VALUE|ID|ID] [options]

   Either of these is required:

       -message VALUE     The notification message.
       -remove ID         Removes a notification with the specified ‘group’ ID.
       -list ID           If the specified ‘group’ ID exists show when it was delivered,
                          or use ‘ALL’ as ID to see all notifications.
                          The output is a tab-separated list.

   Optional:

       -title VALUE       The notification title. Defaults to ‘Terminal’.
       -subtitle VALUE    The notification subtitle.
       -group ID          A string which identifies the group the notifications belong to.
                          Old notifications with the same ID will be removed.
       -activate ID       The bundle identifier of the application to activate when the user clicks the notification.
       -open URL          The URL of a resource to open when the user clicks the notification.
       -execute COMMAND   A shell command to perform when the user clicks the notification.

When the user activates a notification, the results are logged to the system logs.
Use Console.app to view these logs.

Error: Command failed: 
    at ChildProcess.exithandler (child_process.js:647:15)
    at ChildProcess.EventEmitter.emit (events.js:98:17)
    at maybeClose (child_process.js:753:16)
    at Socket.ChildProcess.spawn.stdin (child_process.js:966:11)
    at Socket.EventEmitter.emit (events.js:95:17)
    at Pipe.Socket._destroy._handle.onread [as close] (net.js:465:12)

Process finished with exit code 8

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.