Most desktop environments provide options for customizing keyboard shortcuts. In XFCE, there's settings panels for both for window manager shortcuts and application shortcuts. While the term "application shortcuts" suggests using them for launching applications, and many keyboards do have special keys for launching a music player or a calculator that I do have set up, I don't find myself using those much. I have buttons on my panel for applications that I launch often; if I'm going to be clicking away into a new application, I don't find clicking on the panel to be an additional inconvenience.
On the other hand, "application shortcuts" can be used for launching arbitrary scripts, including ones don't involve switching contexts.
Keys to use#
Many keyboards have extra keys intended for global commands labeled with various symbols. If you have them, you can be creative about what you want them to mean and even combine them with modifiers (Shift, Ctrl, etc.) to get more inputs. On the other hand, if you have a more traditional keyboard layout (which is likely the case on a laptop), your choices are more limited. To avoid confusion, it's generally best to use the Windows key (usually called the Super key in Linux) for global shortcuts as it is not usually used for anything else.
Shortcut ideas#
Volume control#
The most obvious action you might want a shortcut for is volume control (and my focus the last time I wrote about keyboard shortcuts). There are dedicated keys for it on many keyboards. Of course, if you don't have dedicated keys on your keyboard, combinations involving the Super key can be used.
Here's a few PulseAudio commands you might want shortcuts for:
# Toggle mute
pactl set-sink-mute 0 toggle
# Volume up
pactl -- set-sink-volume "0" "+2dB"
# Volume down
pactl -- set-sink-volume "0" "-2dB"
Screenshots#
xfce4-screenshooter
can be called to take
a screenshot of the current window with the -w
option. Take a look at
that page to see what other options you might find useful, including
specifying a directory to save the screenshoot to so the save dialog
doesn't interrupt whatever you were taking a screenshot of.
Killing processes#
xkill
detaches the next window you click on from the X
server, which kills most applications. Often killing an application is
something you want to do urgently or because it is making everything
else run very slowly, so taking the time to open a terminal to type in
xkill
may not be a good option.
Information on windows#
zenity
provides an easy way to provide GUI interactivity
from a shell script run without a terminal to view its output on. For
example, this simple script bound to a global shortcut will show a
dialog box when that shortcut is pressed showing the PID of the process
corresponding to the current window:
#!/bin/sh
zenity --info \
--text "$(xdotool getactivewindow getwindowpid)"
Note that
- Even though this is a shell one-liner, it can't be input into the
XFCE application shortcuts directly as the
$()
operator will not be evaluated as it would in an actual shell. - The XFCE application shortcuts may need the full path to the executable.
And using
~
in the path didn't work for me; it had to be the actual full path.
Modifying windows#
While the window manager settings let you set keyboard controls for many things, there may be some use for more complicated scripts. For instance this script toggles window decorations for the current window.
Or, similar in code to above, you could limit the CPU usage of the current window's process to 10%:
#!/bin/sh
PID="$(xdotool getactivewindow getwindowpid)"
# Run in detached screen to make it easier to stop this later.
screen -d -m -S "cpulimit-$PID" cpulimit -p "$PID" -l 10
Locking the screen#
As it's something I do a lot, it's useful to be able to quickly lock the screen. Super+L is a good shortcut for this as it matches the Windows behavior.
Depending on your setup, exactly how to lock the screen may differ.
xflock4
and xscreensaver-command -lock
both work on my system.
Open application menu#
To open the applications menu, run xfdesktop --menu
(at the cursor)
or xfce4-popup-applicationsmenu
(in the panel). This is equivalent to
the binding of Super or Ctrl+Esc on
Windows.
Other ideas?#
The Wikipedia article on the Windows key lists all of the shortcuts in different versions of Windows, which may include some interesting ideas. What else might you want a global shortcut key for?
Comments
Have something to add? Post a comment by sending an email to comments@aweirdimagination.net. You may use Markdown for formatting.
There are no comments yet.