Last active
October 31, 2023 00:25
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Save class name as variable
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
Updated to launch with specified tabs file and more accurately match window using class name instead of window title