Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a launcher currently on my XFCE panel that I would like to open a window. However, I want to make it only open the window if no other instance is running. If an instance is running, the windows would close upon a press of the launcher. I think that this could be possible with a toggle of the command--if running, close, and if closed, run. How can I achieve this?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

You can install and use wmctrl to do something like what you want.

Say you want to start <program> only if another instance of it isn't running. If another instance of <program> is running, switch to it instead.

Run

wmctrl -a <something> || <program>

or

wmctrl -ax <something> || <program>

depending on which works for you. <something> will be derived from the output of wmctrl -l or wmctrl -lx which you will run when the program you wish to control is open.

You can then assign a shortcut key to that or use it in a script and make a desktop launcher for that script.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.