Skip to content

Instantly share code, notes, and snippets.

@smoser
Created April 7, 2011 16:38
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save smoser/908158 to your computer and use it in GitHub Desktop.
Save smoser/908158 to your computer and use it in GitHub Desktop.
send a message like notify-send without X
#!/bin/sh
# send a notify message without access to DISPLAY
# taken from src/notify-osd.xml in notify-osd and from example in gdbus(1)
# 'notify-send' requires 'DISPLAY' and access to other context
# this script does not
#
# **** UGH ****
# This depends on DBUS_SESSION_BUS_ADDRESS variable, which is still "per-session"
# so, in an environment where you have access to neither, you can't really do this.
#
# src/notify-osd.xml shows
# <method name="Notify">
# <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="stack_notify_handler"/>
# <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
# <arg type="s" name="app_name" direction="in" />
# <arg type="u" name="id" direction="in" />
# <arg type="s" name="icon" direction="in" />
# <arg type="s" name="summary" direction="in" />
# <arg type="s" name="body" direction="in" />
# <arg type="as" name="actions" direction="in" />
# <arg type="a{sv}" name="hints" direction="in" />
# <arg type="i" name="timeout" direction="in" />
# <arg type="u" name="return_id" direction="out" />
# </method>
#
# That is introspectable with:
# gdbus introspect --session \
# --dest org.freedesktop.Notifications \
# --object-path /org/freedesktop/Notifications
app_name="MY APP NAME"
id="42"
# my test shows that gtk-dialog-info can be anything in
# /usr/share/icons/gnome/
icon="ubuntu-logo"
summary="my summary"
body="my bonnie lies over the ocean"
actions="[]"
hints="{}"
timeout="5000" # in milliseconds
exec gdbus call --session \
--dest org.freedesktop.Notifications \
--object-path /org/freedesktop/Notifications \
--method org.freedesktop.Notifications.Notify \
"${app_name}" "${id}" "${icon}" "${summary}" "${body}" \
"${actions}" "${hints}" "${timeout}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment