revision | author | title |
---|---|---|
Sun Apr 09, 2017 15:56:55 |
JM Marcastel |
df_notifier -- user commands |
df_notifier
-- enact macOS user notifications
df_notifier [options]
df_notifier
is a Korn shell script wrapper around Julien Blanchard's Terminal Notifier application that allows to send user
notifications from the command line or shebang'ed shell exec(1)
's. MacOS user notifications, which are available on macOS 10.8
and higher.
Usage of this utility is very straightforward, see the EXAMPLES section below. At a minimum, you must specify either the
--message
, the --remove
, or the --list
option.
-a, --actions=_VALUES_
: Use VALUES
as actions for the notification, where VALUES
is a comma separated list of shell words or strings. Multiple
values will be displayed as a dropdown; you can customize this dropdown label with the --dropdownLabel
option. Does not work
when --reply
is used. [macOS 0.9+].
-A, --activate=_ID_
: Activate the application specified by ID
when the user clicks the notification. You can find the bundle identifier
(CFBundleIdentifier
) of an application in its Info.plist
file inside the application bundle. For instance
com.apple.Terminal
to activate Terminal.app, or com.apple.Safari
to activate Safari.app.
-B, --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.
-C, --close-label
: Use the VALUE
label for the notifications Close
button. [macOS 10.9+].
-e, --execute=_COMMAND_
: Run the shell command COMMAND
when the user clicks the notification.
-g, --group=_ID_
: Specifies the notifications group. For any group, only one notification will ever be shown, replacing previously posted
notifications. A notification can be explicitly removed with the --remove
option. Example group IDs:
- The senders name (to scope the notifications by tool).
- The senders process ID (to scope the notifications by a unique process).
- The current working directory (to scope notifications by project).
-i, --app-icon=_PATH_
: Specify an image PATH
to display instead of the application icon [macOS 10.9+].
-I, --content-image=_PATH_
: Specify an image PATH
to attach inside of the notification [macOS 10.9+].
-j, --json
: Output the event as JSON.
-l, --list=_ID_
: 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. The default value is ALL
.
-L, --dropdown-label=_VALUE_
: Use the VALUE
label for the notifications dropdown menu actions (in which case it is assumed that --actions
contains more
than one action). Does not work when --reply
is used. [10.9+]
-m, --message=_VALUE_
: 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.
-N, --notifier-app=_PATH_
: Use this option or set the environment variable DF_NOTIFIERAPP
to the path of the Terminal Notifier application (e.g.
/Applications/MyRenamed.app
). Otherwise the default name and location will be used. The default value is
/Applications/terminal-notifier.app
.
-o, --open=_URL_
: Open URL
when the user clicks the notification. This can be a web or file URL, or any custom URL scheme.
-r, --remove=_ID_
: Remove a previous notification from the ID
group, if one exists. Use the special ID
ALL
to remove all messages. The
default value is ALL
.
-R, --reply
: Display the notification as a reply type alert [macOS 10.9+].
-s, --subtitle=_VALUE_
: The subtitle of the notification.
-S, --sender=_ID_
: Fakes the sender application of the notification. This uses the specified applications icon, and will launch it when the
notification is clicked. Because this option fakes the notification sender, it cannot be used with options like --execute
,
--open
, and --activate
. For information on the ID
, see the --activate
option.
-t, --title=_VALUE_
: The title of the notification. This defaults to Terminal.
-T, --timeout=_NUMBER_
: Automatically close the alert notification after NUMBER
seconds.
Display piped data with a sound:
echo "Piped Message Data!" | df_notifier --sound default
Multiple actions and custom dropdown list:
df_notifier \
--message "Deploy now on UAT ?" \
--actions Now,"Later today","Tomorrow" \
--dropdownLabel "When ?"
Yes or No ?:
df_notifier \
--title ProjectX \
--subtitle "new tag detected" \
--message "Deploy now on UAT ?" \
--close-label No \
--actions Yes \
--app-icon http://vjeantet.fr/images/logo.png \
Yes or No ? (shorthand notation):
df_notifier -t ProjectX -s "new tag detected" -m "Deploy now on UAT ?" -C No -a Yes -i http:...
Open an URL when the notification is clicked:
df_notifier \
--title="💰" \
--message="Check your Apple stock!" \
--open="http://finance.yahoo.com/q?s=AAPL" \
Open an app when the notification is clicked:
df_notifier \
--group "address-book-sync" \
--title "Address Book Sync" \
--subtitle "Finished" \
--message "Imported 42 contacts." \
--activate "com.apple.AddressBook"
Julien Blanchard's Terminal Notifier application. You can download the binary distribution directly:
https://github.com/julienXX/terminal-notifier/releases
See Julian's GitHub project page for alternate ways of downloading or building this utility:
https://github.com/alloy/terminal-notifier
This script complies to conventional POSIX, UNIX, and Linux conventions through the use of double dashes for long options. If this is not a desired feature and you wish to use a single dash for long options, then you can change the following line in this script:
typeset -S usage=$'[-1]
to:
typeset -S usage=$'[-1p1]
Note however that we do not currently support this modification. It should work out of the box as it doesn't change the logic of the script. However it is not tested. And typically this help text will have to we reworked to comply to the new syntax