Last active
September 23, 2024 17:32
-
-
Save shmup/b2871e3dd09bc7c38bc527971ba16352 to your computer and use it in GitHub Desktop.
Toggle typingmind
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 | |
# example for i3 config: bindsym $mod+Shift+m exec toggle-mind | |
APP_NAME="TypingMind -" | |
APP_LAUNCH_COMMAND="microsoft-edge --app=https://www.typingmind.com" | |
LAUNCH_SLEEP=2 | |
launch_app() { | |
eval "$APP_LAUNCH_COMMAND" & | |
sleep $LAUNCH_SLEEP | |
} | |
# NOTE - let's try searching better, using class. right now we're adding in a " -" to search | |
WINDOW_ID=$(xdotool search --name "$APP_NAME" | head -n 1) | |
if [ -z "$WINDOW_ID" ]; then | |
launch_app | |
exit 0 | |
fi | |
IS_VISIBLE=$(xdotool search --onlyvisible --name "$APP_NAME") | |
FOCUSED_WINDOW=$(xdotool getactivewindow) | |
if [ -z "$IS_VISIBLE" ]; then | |
xdotool windowmap $WINDOW_ID | |
xdotool windowactivate $WINDOW_ID | |
elif [ "$FOCUSED_WINDOW" != "$WINDOW_ID" ]; then | |
xdotool windowactivate $WINDOW_ID | |
else | |
xdotool windowunmap $WINDOW_ID | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment