I have a custom launcher that opens a command such as:

leafpad ~/file1.txt

That opens a specific file that I must work on quite often.

Is it possible to adjust the command so that it is aware if the file has already been open in Leafpad, so by pressing it a second time, it just switches to that file and application, instead of opening a new instance?

  • this may help ... superuser.com/questions/1439340/…
    – jsotola
    Jul 12, 2019 at 2:18
  • @Village Did you have any issue with my answer below working on your system? I tested with leafpad on Debian 9 and had no issue. Thanks
    – jbrock
    Jul 17, 2019 at 3:53

1 Answer 1


You can install wmctrl to achieve this with the following command:

bash -c 'wmctrl -a file1.txt || leafpad ~/file1.txt'

The -a option switches to the window with the title containing file1.txt. However if the command fails, i.e. ||, then it will open your file.

You must log in to answer this question.

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