2

Based on this answer I can activate or minimalize window: how to bring up keepassX window with keyboard shortcut?

xdotool search --onlyvisible --name "My window name" windowactivate
xdotool search --onlyvisible --name "My window name" windowminimize

I assign these commands to two keyboard shortcuts, for example Ctrl+Shift+K and Ctrl+Shift+M.

But I want to have only one keyboard shortcut for toggle window, it means:

if minimalized:
   activate 
else:
   minimalize

I don't see any "toggle" option in xdotool: http://manpages.ubuntu.com/manpages/trusty/man1/xdotool.1.html

OS: Ubuntu, UI: Unity

mkczyk
  • 755

2 Answers2

1

I got this working on X11 KDE plasma:

toggle-window-org-agenda.sh:

#!/usr/bin/env sh

if [[ $(xdotool getactivewindow) -eq $(xdotool search --name "Org Agenda") ]]; then xdotool windowminimize $(xdotool getactivewindow) else xdotool windowactivate $(xdotool search --name "Org Agenda" || emacsclient -e '(progn (org-agenda nil "o") (evil-goto-first-line))' --create-frame && xdotool search --name "Org Agenda") fi

save it to your /home/user/bin folder and invoke it (for example on KDE it's "Custom Shortcuts>Global Command"):

/usr/bin/sh /home/<USERNAME>/bin/toggle-window-org-agenda.sh

Replace all (three) occurrences of "Org Agenda" with something better

0

I often use xdotool with xprop and xev. They both give you a lot of window information.
You could write a simple script that gets information about the window with xprop or xev and implements the if-else block you've written. This is perhaps the most versatile solution, suitable not just for the task you're describing but for all things window management.

Another great tool for tinkering with your window manager is wmctrl. It believe does what you want without scripting:
wmctrl -r "My window name (or id)" -b toggle,hidden

The man page is pretty terse, I found this wmctrl user documentation more elucidating.

Mind that a lot depends on the window manager you use. These tools are EWMH comatible but it can differ a lot how windows are iconified, hidden, sticked, moved to other desktops etc.

micke
  • 3,485
  • 19
  • 29