Notifications from command line

What is the recommended way, from CLI or shell script or cron/timer command to:

  • show a notification

I have figured this out from an TJC thread.
notificationtool -o add --application=MyApp --urgency=2 --icon=icon-s-filled-warning "$title" "$body"
works fine.

But this only places a notification in the notification area. It does not show a popup and it does not trigger a sound. So how do I:

  • show a popup notification
  • trigger a sound

As said I would like to do this without coding an actual application in QML or whatever. Just simple scripting (python is okay if necessary).

Thanks for any pointers!!

3 Likes

Some related threads:

https://together.jolla.com/question/206665/develqml-notification-category-for-im-apps/

https://together.jolla.com/question/78054/how-to-check-notifications-via-command-line/

1 Like

The trick is to add a couple of extra ‘hints’ to the call. So if you do this:

notificationtool -o add --application=MyApp --urgency=2 --icon=icon-s-filled-warning "title" "body" --hint="x-nemo-preview-summary Popup summary" --hint="x-nemo-preview-body Popup body text"

you should get the popup as well. If you want to do it without having to install the lipstick-qt5-tools package, you can also call the dbus interface directly (I’m pretty sure gdbus is installed by default). Admittedly a bit more cumbersome, but fine if it’s going in a script.

gdbus call --session --dest org.freedesktop.Notifications --object-path /org/freedesktop/Notifications --method org.freedesktop.Notifications.Notify MyApp 42 "icon-s-filled-warning" "Summary" "Body" "[]" "{'x-nemo-preview-summary':<'Popup summary'>, 'x-nemo-preview-body':<'Popup body text'>}" 0

Incidentally, in case it’s helpful for future reference, apart from the sailfish-specific parts I got this example from man gdbus.

I’m not sure about sound/vibration though.

8 Likes

Thinking more about the sound, you could probably use something like this to play a sound at the same time. The paplay call blocks, so probably you’d want to trigger the notification first.

paplay /usr/share/sounds/jolla-ringtones/stereo/jolla-messagetone.ogg

There’s probably a better way to do this, but maybe it’ll be enough.

5 Likes

Thank you very much, the preview/popup works perfectly.

In fact, you don’t need hints really, notificationtool uses the last two parameters as popup title and content:

notificationtool <options> title text popuptitle popuptext

Vibration started to appear as well.

3 Likes

I compiled and ran this tool here successfully on SFOS 3.3

1 Like

@SGE, notify-desktop and notify-send (usually part of the RPM file libnotify) are not provided by Jolla for SailfishOS, neither installed by default or available in Jolla’s RPM repositories.
In contrast to that notificationtool, gdbus and dbus-send are installed by default and work fine, hence I see no reason to compile and install a fourth tool, because one would have to maintain that by oneself, while three such tools maintained by Jolla for SailfishOS exist.

  • notificationtool is simple to use, see notificationtool --help
  • gdbus is easy to use, see gdbus --help / gdbus call --help; still it allows to send arbitrary signals and method-calls via D-bus.
  • dbus-send also allows to send arbitrary signals and method-calls via D-bus.

Just for sake of completeness, there is also busctl from systemd to interact with dbus services.

1 Like