i3 switch-to-or-launch application shortcut if it's already open, don't open it again
On my computer, I hit a 2-key combo to either launch emacs, or switch focus to the existing window if emacs is already running—even if it’s on another workspace. I do the same for Firefox.
I found this to be a very convenient hotkey and was surprised it’s not in the current i3wm documentation. Searching online now, I see it in the old FAQ with suggestions for a bash script and even a python script, but the truth is, it’s a small one-liner. In fact this is better without a script as it lends itself to a different execution command, like placing on a workspace or setting environment variables. So, I figured this warrants a quick post.
## quick shortcuts from oribarbut.com
# start or switch to emacs
bindsym $mod+x exec pgrep emacs && i3-msg '[class="Emacs"] focus' || emacs
# start or switch to firefox
bindsym $mod+b exec pgrep firefox && i3-msg '[class="Firefox"] focus' || firefox
The same sort of command would work for You’ll just need to change how the key is bound, and look up how your window manager is programmatically told to change focus , tiling or otherwise. I recommend it for any program you find yourself using constantly.
If you have any questions or suggestions, or even if you just found this post useful, send me an email and let me know! I would love to hear from you and it feels nice to know that the content I write is being read.
For more related content, look at my other posts on software, or under the tags emacs and i3wm. And for other topics, see thoughts and projects on the homepage. This website is my little way to give back to the world wide web. If you like this kind of post, you can sign up to a periodic email about new content (no spam and painless to unsubscribe), follow my fairly quiet twitter account, or subscribe to this website in your favorite RSS reader.
There's no comments section on this website, but if I get a notable question or comment I will include it here manually—and in that case I will ask beforehand if/how you'd like to be credited or anonymous.