index.html :: rss :: github :: telegram :: email

xdotool: the "toggle window" feature

11 Apr 2025

tl;dr: the script.

the idea is to switch to a terminal window, with the single hotkey, no matter what application is on a foreground now. iterm2 on macos has such feature natively, and i've been using it for a decade, and now it is an essence of my workflow. so, let's invent something to make this available on linux, too.

man 1 xdotool says:

xdotool lets you programmatically (or manually) simulate
keyboard input and mouse activity, move and resize windows, etc.

and that's is exactly what we are looking for!

the idea is rather simple: query active and target windows by its class name, compare ids, and activate/minimize the target window accordinly.

how to use the scipt? bind it to a hotkey in your window manager config, passing window class as an argument, e.g for fluxbox:

$ cat ~/.fluxbox/keys | grep x-toggle
F19 :ExecCommand /home/alex/src/dotfiles/shared/x-toggle-window ghostty
Mod1 F12 :ExecCommand /home/alex/src/dotfiles/shared/x-toggle-window firefox