Site Map - skip to main content

Hacker Public Radio

Your ideas, projects, opinions - podcasted.

New episodes every weekday Monday through Friday.
This page was generated by The HPR Robot at


hpr2094 :: Custom Keystrokes for Desktop Navigation on Gnome

I demonstrate how to add custom keystrokes for desktop navigation on classic gnome

<< First, < Previous, , Latest >>

Thumbnail of Jon Kulp
Hosted by Jon Kulp on 2016-08-11 is flagged as Clean and is released under a CC-BY-SA license.
Scripting, Linux, Desktop Environments, Accessibility. 3.
The show is available on the Internet Archive at: https://archive.org/details/hpr2094

Listen in ogg, spx, or mp3 format. Play now:

Duration: 00:14:04

Accessibility.

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.

#!/bin/bash

# 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.
    
  else
    loffice &
fi

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.


Comments

Subscribe to the comments RSS feed.

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" else loffice & fi

It can reduce script complexity a fair bit.

Comment #2 posted on 2016-08-25 16:49:58 by Jon Kulp

Good tip

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

grep -q

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.

Leave Comment

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 :).

Provide feedback
Your Name/Handle:
Title:
Comment:
Anti Spam Question: What does the letter P in HPR stand for?
Are you a spammer?
What is the HOST_ID for the host of this show?
What does HPR mean to you?