Terminal-notifier



  1. Terminal-notifier Change Icon
  2. Terminal-notifier Python
  3. Applescript Display Alert

Using terminal notifier in our capfiles Thursday, January 02, 2014 by Miles Matthias We use capistrano for our deployments and recently I came across the sweet terminal-notifier gem that uses the user notifications in OS X 10.8 and above to show a nice notification from the command line.

  1. Terminal-notifier is a tool in the RubyGems Packages category of a tech stack. Terminal-notifier is an open source tool with 5.5K GitHub stars and 318 GitHub forks. Here’s a link to terminal-notifier 's open source repository on GitHub.
  2. Terminal-notifier is a command-line tool to send macOS User Notifications, which are available on macOS 10.10 and higher.

Terminal Notifier is a command-line tool to send notifications from command line, which are available since Mac OS X 10.8 and newer. Useful when something happens in a script you wrote.

For example, you could get a notification every time rkhunter does a check. Or use it when you write a cronjob for something. The posibilities are endless. Everything you need to install this is homebrew and the following command: brew install terminal-notifier.

Usage

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

Alert

Note that in some circumstances the first character of a message has to be escaped in order to be recognized.
An example of this is when using an open bracket, which has to be escaped like so:
'['

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

News

alerter features were merged in terminal-notifier 1.7. This led to some issues and even more issues in the 1.8 release. We decided with Valère Jeantet to rollback this merge.

From now on terminal-notifier won't have the sticky notification feature nor the actions buttons. If you need them please use alerter. I also want to follow semver hence this latest version starts at 2.0.0.

Sticking to two smaller specialized tools will hopefully make them easier to maintain and less error prone.

Caveats

  • It is currently packaged as an application bundle, because NSUserNotificationdoes not work from a ‘Foundation tool’. radar://11956694

  • If you intend to package terminal-notifier with your app to distribute it on the Mac App Store, please use 1.5.2; version 1.6.0+ uses a private method override, which is not allowed in the App Store Guidelines.

  • If you're using macOS < 10.10 you should use terminal-notifier 1.6.3.

  • If you're looking for sticky notifications or more actions on a notification please use alerter

Download

Prebuilt binaries are available from thereleases section.

Or if you want to use this fromRuby, you caninstall it through RubyGems:

You can also install it via Homebrew:

Usage

In order to use terminal-notifier, you have to call the binary inside theapplication bundle.

The Ruby gem, which wraps this tool, does have a bin wrapper. If installedyou can simply do:

This will obviously be a bit slower than using the tool without the wrapper.

If you'd like notifications to stay on the screen until dismissed, go to System Preferences -> Notifications -> terminal-notifier and change the style from Banners to Alerts. You cannot do this on a per-notification basis.

Example Uses

Display piped data with a sound:

Use a custom icon:

Open an URL when the notification is clicked:

Open an app when the notification is clicked:

Options

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

-message VALUE[required]

The message body of the notification.

If you pipe data into terminal-notifier, you can omit this option,and the piped data will become the message body instead.

-title VALUE

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

-subtitle VALUE

The subtitle of the notification.

-sound NAME

Play the NAME sound when the notification appears.Sound names are listed in Sound Preferences.

Use the special NAME “default” for the default notification sound.

-group ID

Specifies the notification’s ‘group’. For any ‘group’, only onenotification will ever be shown, replacing previously posted notifications.

A notification can be explicitly removed with the -remove option (seebelow).

Example group IDs:

  • 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]

Remove a previous notification from the ID ‘group’, if one exists.

Use the special ID “ALL” to remove all messages.

-list ID[required]

Lists details about the specified ‘group’ ID.

Use the special ID “ALL” to list details about all currently active messages.

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

-activate ID

Activate the application specified by ID when the user clicks thenotification.

You can find the bundle identifier (CFBundleIdentifier) of an application in its Info.plist fileinside the application bundle.

Examples application IDs are:

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

-sender ID

Fakes the sender application of the notification. This uses the specifiedapplication’s icon, and will launch it when the notification is clicked.

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

For information on the ID, see the -activate option.

-appIcon PATH

Terminal-notifier Change Icon

Specify an image PATH to display instead of the application icon.

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

-contentImage PATH

Specify an image PATH to attach inside of the notification.

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

-open URL

Open URL when the user clicks the notification. This can be a web or file URL,or any custom URL scheme.

-execute COMMAND

Run the shell command COMMAND when the user clicks the notification.

-ignoreDnD

Ignore Do Not Disturb settings and unconditionally show the notification.

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

License

All the works are available under the MIT license. Except for‘Terminal.icns’, which is a copy of Apple’s Terminal.app icon and as such iscopyright of Apple.

Terminal-notifier Python

Copyright (C) 2012-2017 Eloy Durán eloy.de.enige@gmail.com, Julien Blanchardjulien@sideburns.eu

Permission is hereby granted, free of charge, to any person obtaining a copy ofthis software and associated documentation files (the 'Software'), to deal inthe Software without restriction, including without limitation the rights touse, copy, modify, merge, publish, distribute, sublicense, and/or sell copiesof the Software, and to permit persons to whom the Software is furnished to doso, subject to the following conditions:

Applescript Display Alert

Applescript

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

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, 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 THESOFTWARE.