Created
December 31, 2021 22:46
-
-
Save kugland/79e0759b307182004743411c04e15026 to your computer and use it in GitHub Desktop.
Toggle yakuake’s window; if it’s not running, start it and then show the window. (So you don’t have to reopen it manually in case you accidentally closed it.)
This file contains hidden or 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
#!/bin/bash | |
# Toggle yakuake's window; if it's not running, start it and then show the window. | |
# (So you don't have to reopen it manually in case you accidentally closed it.) | |
# | |
# To use this script, install it to /usr/local/bin/toggle-yakuake, then disable | |
# yakuake's global shortcut, and create a global shortcut pointing to this script. | |
# | |
# Written by André Kugland | |
die() { | |
if [[ -e /usr/bin/kdialog ]]; then | |
kdialog --icon error --passivepopup "$1" 5 | |
else | |
echo "$1" | |
fi | |
exit 1 | |
} | |
YAKUAKE_BIN=/usr/bin/yakuake | |
if [[ ! -e "$YAKUAKE_BIN" ]]; then | |
die "No executable found at '${YAKUAKE_BIN}'." | |
fi | |
# Check if yakuake's DBus interface is available | |
is_yakuake_ready() { | |
if qdbus org.freedesktop.DBus / org.freedesktop.DBus.ListNames | fgrep org.kde.yakuake >/dev/null 2>&1; then | |
return 0 | |
else | |
return 1 | |
fi | |
} | |
# Wait 5s for yakuake's DBus interface to become available, pooling every 0.1s. | |
# If after 5s it doesn't become available, give up. | |
wait_for_yakuake() { | |
for i in {0..50}; do | |
is_yakuake_ready && return 0 | |
sleep .1 | |
done | |
return 1 | |
} | |
if ! is_yakuake_ready; then | |
( "$YAKUAKE_BIN" >/dev/null 2>&1 & ) | |
if ! wait_for_yakuake; then | |
# Something went terribly wrong. | |
die 'Unable to start yakuake.' | |
fi | |
fi | |
qdbus org.kde.yakuake /yakuake/window org.kde.yakuake.toggleWindowState |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment