Site Map - skip to main content - dyslexic font - mobile - text - print

Hacker Public Radio

Your ideas, projects, opinions - podcasted.

New episodes Monday through Friday.


hpr2094 :: Custom Keystrokes for Desktop Navigation on Gnome

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

<< First, < Previous, Latest >>

Host Image
Hosted by Jon Kulp on 2016-08-11 is flagged as Clean and is released under a CC-BY-SA license.
Listen in ogg, spx, or mp3 format. | Comments (3)

Part of the series: 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-24T18:56:13Z 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-25T16:49:58Z 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-25T17:31:42Z 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

Powered by Comment Script