Created
April 16, 2022 13:03
-
-
Save takikoo/80be04058ed8a871912a021f05e880d6 to your computer and use it in GitHub Desktop.
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 | |
# Script that either brings the app to focus or launches it. | |
if [[ $# -eq 0 ]] ; then | |
echo 'Please provide an app name' | |
exit 0 | |
fi | |
APP=$@ | |
APP_PID=$(xdotool search --class $APP | tail -n1) | |
APP_PID_FOCUSED=$(xdotool getactivewindow) | |
if [ -z "$APP_PID" ]; then | |
# APP is not running | |
case "$APP" in | |
"brave") | |
notify-send "Starting $APP" | |
/usr/bin/brave & | |
;; | |
"discord") | |
notify-send "Starting $APP" | |
/usr/bin/discord & | |
;; | |
"kitty") | |
notify-send "Starting $APP" | |
/usr/bin/kitty & | |
;; | |
"slack") | |
notify-send "Starting $APP" | |
/usr/bin/slack & | |
;; | |
"teams") | |
notify-send "Starting $APP" | |
/var/lib/snapd/snap/bin/teams & | |
;; | |
"eclipse") | |
notify-send "Starting $APP" | |
/usr/bin/eclipse & | |
;; | |
*) | |
"$APP not defined"; | |
exit 0; | |
;; | |
esac | |
else | |
# APP has already launched | |
if [[ "$APP_PID_FOCUSED" == "$APP_PID" ]]; then | |
# APP already has focus, try to find a second window | |
APP_PID=$(xdotool search --class $APP | tail -2 | head -1) | |
fi | |
# Launching APP | |
xdotool windowactivate --sync $APP_PID | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment