Shows about tearing down the barriers for our fellow hackers.
In this episode I talk about how to set up custom keystrokes so that you can launch or switch to applications easily using the super key on your keyboard. I do this on the classic Gnome desktop environment and have not tested it on Gnome 3 or Unity to see whether it works on those.
To create a new custom keystroke, open System Settings, then go to Keyboard and Shortcuts. Click on the plus sign to open the dialog box where you specify the name of the keystroke and the command that is to be launched when the keystroke is executed. Click "Apply" and then click "Disabled" and it will allow you to type the keystroke you want to use.
At this point the keystroke configuration is ready, but you have to either log out of the current session and log back in, or find some other way to reload the desktop environment configuration before you can actually use the keystroke.
I also talked about how I use my own scripts to check to see whether a program is running, and then either switch to that program if it's running or launch it if it's not. Here is an example for launching or switching to LibreOffice.
# Look for the string "LibreOffice" on the list of
# window titles and check the return code
checktitle=$(wmctrl -l | grep "LibreOffice" &> /dev/null ; echo $?)
# If the return code is 0 that means it found the
# string, so I use wmctrl to switch to the window
# that has that string in the title.
if [ $checktitle == 0 ] ; then
wmctrl -a "LibreOffice"
# If it returns a 1, then that means it did not
# find a window with that string in it so I
# launch the application.
Save the script somewhere in your PATH, make it executable, and then use the script name in the command when you're setting up the keystroke.
Comment #1 posted on 2016-08-24 18:56:13 by Dave Morriss
Using grep in a script
One thing I have learned while writing Bash scripts (for the hell of it sometimes) is that 'grep -q' is useful for direct use in 'if' expressions.
You could do:
if wmctrl -l | grep -q "LibreOffice"; then
wmctrl -a "LibreOffice"
It can reduce script complexity a fair bit.
Comment #2 posted on 2016-08-25 16:49:58 by Jon Kulp
Aha! Very nice tip! It would save us having to redirect stuff to /dev/null, wouldn't it?
Comment #3 posted on 2016-08-25 17:31:42 by Dave Morriss
Yes, 'grep -q' simply returns a zero (true) result if a match is found and writes nothing on standard output.
I didn't know about this until relatively recently. The original Unix 'grep' I encountered didn't have this and you'd have to do things the way you did in your script. GNU grep was enhanced with many such features, which I think was a good thing personally. Others prefer the old "clean" way.
Note to Verbose Commenters
If you can't fit everything you want to say in the comment below then you really should record a response show instead.
Note to Spammers
All comments are moderated. All links are checked by humans. We strip out all html. Feel free to record a show about yourself, or your industry, or any other topic we may find interesting. We also check shows for spam :).