diff --git a/bin/desktop/youtube-music/controller.sh b/bin/desktop/youtube-music/controller.sh index 57ae275..f41a757 100755 --- a/bin/desktop/youtube-music/controller.sh +++ b/bin/desktop/youtube-music/controller.sh @@ -1,16 +1,12 @@ # # Chrome / YouTube only accepts keypresses when window is active # -# This activates the YouTube window, sends the keypress, then reactivates the original window +# This activates the YouTube window and sends the keypress # xdotool search --name 'YouTube Music' >/dev/null 2>&1 || return 1; -ACTIVE_DESKTOP="$(xdotool get_desktop)" -ACTIVE_WINDOW_ID="$(xdotool getactivewindow)" -ACTIVE_WINDOW_NAME="$(xdotool getwindowname $ACTIVE_WINDOW_ID)" - -TIMEOUT='0.1'; +TIMEOUT='0.3'; case $1 in next) KEY_COMMAND='j';; @@ -21,6 +17,3 @@ esac xdotool search --name 'YouTube Music' windowactivate; sleep $TIMEOUT; xdotool key --clearmodifiers "$KEY_COMMAND"; - -xdotool set_desktop "$ACTIVE_DESKTOP"; -[[ "$ACTIVE_WINDOW_NAME" != "Desktop" ]] && xdotool windowactivate "$ACTIVE_WINDOW_ID"; diff --git a/bin/desktop/youtube-music/return-controller.sh b/bin/desktop/youtube-music/return-controller.sh new file mode 100755 index 0000000..57ae275 --- /dev/null +++ b/bin/desktop/youtube-music/return-controller.sh @@ -0,0 +1,26 @@ +# +# Chrome / YouTube only accepts keypresses when window is active +# +# This activates the YouTube window, sends the keypress, then reactivates the original window +# + +xdotool search --name 'YouTube Music' >/dev/null 2>&1 || return 1; + +ACTIVE_DESKTOP="$(xdotool get_desktop)" +ACTIVE_WINDOW_ID="$(xdotool getactivewindow)" +ACTIVE_WINDOW_NAME="$(xdotool getwindowname $ACTIVE_WINDOW_ID)" + +TIMEOUT='0.1'; + +case $1 in + next) KEY_COMMAND='j';; + prev) KEY_COMMAND='k';; + *) KEY_COMMAND='space';; +esac + +xdotool search --name 'YouTube Music' windowactivate; +sleep $TIMEOUT; +xdotool key --clearmodifiers "$KEY_COMMAND"; + +xdotool set_desktop "$ACTIVE_DESKTOP"; +[[ "$ACTIVE_WINDOW_NAME" != "Desktop" ]] && xdotool windowactivate "$ACTIVE_WINDOW_ID";