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.