Skip to content

Send User Alert Notification on Mac OS X from the command-line.

License

Notifications You must be signed in to change notification settings

vjeantet/alerter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Alerter

alerter is a command-line tool to send Mac OS X User Alerts (Notifications), which are available in Mac OS X 10.8 and higher. the program ends when the alerter is activated or closed, wrinting a json struct to output (stdout) to describe the alert event.

Alerts are osx notifications that stay on screen unless dismissed.

2 kinds of alert notification can be triggered : "Reply Alert" or "Actions Alert"

Reply alert

Open a notification in the top-right corner of your screen and display a "Reply" button, which opens a text input.

Actions alert

Open a notification in the top-right corner of your screen and display one or more actions to click on.

Features

  • set alert's icon, title, subtitle, image.
  • capture text typed by user in the reply type alert.
  • timeout : automatically close the alert notification after a delay.
  • change the close button label.
  • change the actions dropdown label.
  • play a sound while delivering the alert notification.
  • json output on alert's event (closed, timeout, replied, activated...)
  • close the alert notification on SIGINT, SIGTERM.

Download

Prebuilt binaries are available from the releases section.

Usage

$ ./alerter -[message|group|list] [VALUE|ID|ID] [options]

Some examples are:

Display piped data with a sound

$ echo 'Piped Message Data!' | alerter -sound default

Alt text

Multiple actions and custom dropdown list

./alerter -message "Deploy now on UAT ?" -actions Now,"Later today","Tomorrow" -dropdownLabel "When ?"

Alt text

Yes or No ?

./alerter -title ProjectX -subtitle "new tag detected" -message "Deploy now on UAT ?" -closeLabel No -actions Yes -appIcon https://vjeantet.fr/images/logo.png

Alt text

What is the name of this release ?

./alerter -reply -message "What is the name of this release ?" -title "Deploy in progress..."

Alt text

Options

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


-message VALUE [required]

The message body of the notification.

Note that if this option is omitted and data is piped to the application, that data will be used instead.


-reply

The notification will be displayed as a reply type alert.


-actions VALUE1,VALUE2,"VALUE 3"

The notification actions avalaible. When you provide more than one value, a dropdown will be displayed. You can customize this dropdown label with the next option Does not work when -reply is used


-dropdownLabel VALUE

The notification actions dropdown title (only when multiples -actions values are provided). Does not work when -reply is used


-closeLabel VALUE

The notification "Close" button label.


-title VALUE

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


-subtitle VALUE

The subtitle of the notification.


-timeout NUMBER

Auto close the alert notification after NUMBER seconds.


-sound NAME

The name of a sound to play when the notification appears. The names are listed in Sound Preferences. Use 'default' for the default notification sound.


-outputEvent

Alerter outputs a json struct to describe what happened to the alert. With this option, Alerter will only output a string value to describe the event.

  • @CLOSED - When the user clicks on the close button (If you changed its label with -closeLabel, your value will be outputed instead of @CLOSED)
  • @CONTENTCLICKED - When the user clicks on the notification content
  • @TIMEOUT - Alert closed after a delay (see -timeout)
  • @ACTIONCLICKED - When the user clicks on the default action (Show).
  • VALUE - the text typed by the user in the alert reply input text
  • VALUE - When user click on a customized action (see --actions)

-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 a json array of alert notifications.


-sender ID

Specifying this will make it appear as if the notification was send by that application instead, including using its icon.

Using this option fakes the sender application, so that the notification system will launch that application when the notification is clicked. Because of this it is important to note that you cannot combine this with options like -execute, -open, and -activate which depend on the sender of the notification to be ‘alerter’ to perform its work.

For information on the ID see the -activate option.


-appIcon PATH [10.9+ only]

Specifies The PATH or URL of an image to display instead of the application icon.

WARNING: This option is subject to change since it relies on a private method.


-contentImage PATH [10.9+ only]

Specifies The PATH or URL of an image to display attached inside the notification.

WARNING: This option is subject to change since it relies on a private method.


Source code

This project is based on a fork of terminal notifier by @JulienXX.

License

All the works are available under the MIT license.

Copyright (C) 2012-2015 Valère Jeantet [email protected], Eloy Durán [email protected], Julien Blanchard [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.