1

I got used to Win+(1..9) hotkeys in windows 7+, and would like to implement something like this in LXDE.

So, I need to define a hotkey that will:

  • launch defined application if it is not launched yet, OR

  • switch me to that application if it's already running.

How this can be done?

I can check if app is running using ps -e | grep appname, but is there are any ways to make LXDE switch to app by its name or PID using command line? Or, maybe there are any other ways to do all this?

I've been implementing such behaviour in WinXP using AutoHotkey. In Win7/Win8 it's native. And it's very useful, so I'd like to use it in my Debian too.

1 Answer 1

0

Unix doesn't exactly have a concept of “application”. Rather than using processes, toplevel windows would be a better indicator. They're easier to detect precisely, and you won't falsely detect applications of another user.

Each window has a class that identifies its application. To see the class name for an application, run the following command in a terminal and click on the application's window:

xprop WM_CLASS

This displays two strings: the instance name and the class name.

The most useful tools to display information about windows and perform some basic actions on them are xdotool and wmctrl.

With wmctrl, you can use wmctrl -F -x -a "$instance.$class" to activate one of the windows with the given instance and class. If there is no matching window, wmctrl returns an error status, so you can then choose to launch the program. Example:

wmctrl -F -x -a Navigator.Firefox || firefox &

The equivalent xdotool command:

xdotool search --class --maxdepth 2 Firefox windowactivate || firefox &

If there are multiple toplevel windows, there's no easy way to determine which one will be activated. To activate the most recent one, you'd need the cooperation of your window manager — Openbox by default in LXDE. I'm not familiar with Openbox, but it's fairly lean, so it might not offer a way to report the most recently activated window. I think LXDE can be used with other window managers such as sawfish which is programmable so you could code this functionality inside the window managers in a few lines of code.

Use your window manager's key binding setting mechanism to bind the keys you want to one of these commands.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .