Handlers speculative: how to get a random word notifier in GNOME 3

I’ve been using my “fan merinos” random word generating script for a long time, and increasingly regularly as I take part in a few forums with transient pseudonymity and it’s a useful way to quickly get a pseudonym:

$ rw 1
mortally

Sure. Pseudonym activate. Yours, “Mortally”.

The result has been though that I increasingly return to my desktop to find that I’ve opened about 15 terminals and run rw in each and abandoned them.

How useful it would be to have a GNOME notification generated via a keyboard shortcut! Eg I could press Ctrl+Alt+R and get:

A GNOME notification reading: convalescence identities teases handlers speculative

Putting all this together takes a bit of work. First, the shell script to create the notification:

#!/bin/bash

WORDS=/usr/share/dict/words
NUM_WORDS=5 # fits nicely in a notification for me

notify-send "$(cat "$WORDS" | grep -v "'" | grep -v "[A-Z]" | shuf -n $NUM_WORDS | xargs echo)" -a "Random words"

Save to, eg ~/bin/rw-notify.sh, and then make it executable: chmod 700 ~/bin/rw-notify.sh

If you run the command from a terminal you then get the notification.

But for some reason I haven’t worked out, GNOME’s keyboard shortcuts won’t run a shell script. If you try and add a shortcut that runs this command, it will simply do nothing.

So, next create another file: ~/.local/share/applications/rw-notify.desktop:

#!/usr/bin/exo-open
[Desktop Entry]
Name=Random Words Notify
Exec=[YOUR HOME DIR]/bin/rw-notify.sh
Type=Application

Replacing [YOUR HOME DIR] with the location of your home dir, eg:

Exec=/home/mary/bin/rw-notify.sh

This will let you activate an application called “Random Words Notify” from the GNOME launcher.

Last step, binding it to a key.

First, you need to have /usr/bin/exo-open available on your system (for some context, see GNOME bug 343896). On Debian and Ubuntu, you’ll need to install exo-utils and on Fedora exo.

You will also need to make the desktop file itself executable: chmod 700 ~/.local/share/applications/rw-notify.desktop

Now, finally open the keyboard shortcuts editor (open the Activities view and start typing “Keyboard”). Scroll to the bottom and press the + to add a new custom shortcut:

Screenshot of the GNOME keyboard shortcut dialog

Then press “Set shortcut” followed by the keys you want (in my case, Ctrl+Alt+R), and fill in a name and, as the command, the full path of the rw-notify.desktop file, eg /home/mary/.local/share/applications/rw-notify.desktop:

Screenshot of the GNOME Add Custom Shortcut dialog

Press “Add” and now Ctrl+Alt+R will bring up 5 random words in a notification for you:

A GNOME notification reading: convalescence identities teases handlers speculative

All shell scripts and commands in this post (enclosed in the <code> HTML tags) are in the public domain.