Skip to content

Instantly share code, notes, and snippets.

@GrayedFox
Last active October 31, 2023 00:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GrayedFox/d596c7896aad4b3cea441037c890f826 to your computer and use it in GitHub Desktop.
Save GrayedFox/d596c7896aad4b3cea441037c890f826 to your computer and use it in GitHub Desktop.
A script to show and hide the konsole application, useful when bound to a custom keyboard shortcut.
#!/usr/bin/env bash
# if konsole is not open launch it
if [ -z "$(xdotool search --class konsole)" ]; then
konsole --tabs-from-file "/home/grayedfox/.config/konsole-tabs"
fi
# get current focused window and visible konsole window
CLASS="konsole"
KONSOLE_ID="$(xdotool search --class $CLASS | awk '{print $1}')"
KONSOLE_WINDOW="$(xdotool search --onlyvisible --class $CLASS)"
ACTIVE_WINDOW="$(xdotool getactivewindow)"
ACTIVE_DESKTOP="$(xdotool get_desktop)"
# if focused, minimize and hide the konsole, otherwise bring konsole to current desktop and open
if [ "$ACTIVE_WINDOW" = "$KONSOLE_WINDOW" ]; then
xdotool getactivewindow windowminimize
else
xdotool set_desktop_for_window $KONSOLE_ID $ACTIVE_DESKTOP
xdotool windowraise $KONSOLE_ID
fi
@GrayedFox
Copy link
Author

Updated to launch with specified tabs file and more accurately match window using class name instead of window title

@GrayedFox
Copy link
Author

Save class name as variable

@GrayedFox
Copy link
Author

GrayedFox commented Oct 30, 2023

Removed wmctrl dependency so that only xodotool is used - previous version was using wmctrl to make sure the application always appeared on the active workspace (current desktop), but this introduced an extra dependency. The same functionality can be achieved using xodotool so long as we can reliably get the active desktop.

As an added bonus, plays nicely with Workspace Matrix extension.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment