From 55860882e27bf2edef362f1babb27059ab72cb34 Mon Sep 17 00:00:00 2001 From: iberniex Date: Sat, 19 Jul 2025 17:03:44 +0300 Subject: [PATCH 1/8] patch: add remote guard This patch is related to the spr plugin remote option in which it was conflicting with the mac-player plugin in which it was displaying the osascript scripts from this plugin. --- scripts/mac-player.sh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/scripts/mac-player.sh b/scripts/mac-player.sh index f4ae62c8..9dda9546 100755 --- a/scripts/mac-player.sh +++ b/scripts/mac-player.sh @@ -178,10 +178,6 @@ function remoteControl() { tmux bind-key "$toggle_button" run-shell "$toggle" tmux bind-key "$back_button" run-shell "$back" tmux bind-key "$next_button" run-shell "$next" - else - tmux unbind-key "$toggle_button" - tmux unbind-key "$back_button" - tmux unbind-key "$next_button" fi } @@ -217,7 +213,10 @@ main() { # Remote Access if [[ "$REMOTE_ACCESS" == true ]]; then remoteControl "$PLAY_PAUSE_BUTTON" "$BACK_BUTTON" "$NEXT_BUTTON" "$REMOTE_APP" - + else + tmux unbind-key "$toggle_button" + tmux unbind-key "$back_button" + tmux unbind-key "$next_button" fi if [ ! -f "$cache_file" ] || [ $(($(date +%s) - $(stat -f%c "$cache_file"))) -ge "$RATE" ]; then From 039b1587031cd48a29962081460eaa23acd111fa Mon Sep 17 00:00:00 2001 From: iberniex Date: Sat, 19 Jul 2025 19:43:08 +0300 Subject: [PATCH 2/8] patch: distinguish back track for apple music and player position for spotify there was error of using the R keybind that was not working with spotify and leading to the issues of spotify not working well. --- scripts/mac-player.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/mac-player.sh b/scripts/mac-player.sh index 9dda9546..071df229 100755 --- a/scripts/mac-player.sh +++ b/scripts/mac-player.sh @@ -167,8 +167,12 @@ function remoteControl() { if [[ $app_controlled == "Spotify" ]] || [[ $app_controlled == "Music" ]]; then + if [[ $app_controlled == "Music" ]]; then + back="osascript -e 'tell application \"$app_controlled\" to back track'" + else + back="osascript -e 'tell application \"$app_controlled\" to set player position to 0'" + fi toggle="osascript -e 'tell application \"$app_controlled\" to playpause'" - back="osascript -e 'tell application \"$app_controlled\" to back track'" next="osascript -e 'tell application \"$app_controlled\" to play next track'" tmux unbind-key "$toggle_button" From 6792c16449469b4ce6016b17f342cbfed4279a97 Mon Sep 17 00:00:00 2001 From: iberniex Date: Sat, 19 Jul 2025 19:43:46 +0300 Subject: [PATCH 3/8] patch: remote control patch for preventing leaks --- scripts/mac-player.sh | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/scripts/mac-player.sh b/scripts/mac-player.sh index 071df229..f7ab3a7f 100755 --- a/scripts/mac-player.sh +++ b/scripts/mac-player.sh @@ -198,16 +198,9 @@ main() { MAX_LENGTH=$(get_tmux_option "@dracula-mac-player-length" 25) # Remote variables - REMOTE_ACCESS=$(get_tmux_option "@dracula-mac-player-remote" false) + REMOTE_ACCESS=$(get_tmux_option "@dracula-mac-player-remote" "false") REMOTE_APP=$(get_tmux_option "@dracula-mac-player-app" "Spotify") - # Remote Control Buttons Customizations - PLAY_PAUSE_BUTTON=$(get_tmux_option "@dracula-mac-player-remote-play-pause" "P") - BACK_BUTTON=$(get_tmux_option "@dracula-mac-player-remote-back" "R") - NEXT_BUTTON=$(get_tmux_option "@dracula-mac-player-remote-next" "N") - - - # os checker if [[ "$OSTYPE" != "darwin"* ]]; then echo "" @@ -215,12 +208,12 @@ main() { fi # Remote Access - if [[ "$REMOTE_ACCESS" == true ]]; then + if [[ "$REMOTE_ACCESS" == "true" ]]; then + # Remote Control Buttons Customizations + PLAY_PAUSE_BUTTON=$(get_tmux_option "@dracula-mac-player-remote-play-pause" "P") + BACK_BUTTON=$(get_tmux_option "@dracula-mac-player-remote-back" "R") + NEXT_BUTTON=$(get_tmux_option "@dracula-mac-player-remote-next" "N") remoteControl "$PLAY_PAUSE_BUTTON" "$BACK_BUTTON" "$NEXT_BUTTON" "$REMOTE_APP" - else - tmux unbind-key "$toggle_button" - tmux unbind-key "$back_button" - tmux unbind-key "$next_button" fi if [ ! -f "$cache_file" ] || [ $(($(date +%s) - $(stat -f%c "$cache_file"))) -ge "$RATE" ]; then From 17ab869c21efa7f51cc474b5557f4c340f2d0f6c Mon Sep 17 00:00:00 2001 From: iberniex Date: Sat, 19 Jul 2025 19:45:13 +0300 Subject: [PATCH 4/8] fix: DRYing code catting the cache file alot of times would leading to increased latency. --- scripts/mac-player.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/mac-player.sh b/scripts/mac-player.sh index f7ab3a7f..92419bae 100755 --- a/scripts/mac-player.sh +++ b/scripts/mac-player.sh @@ -217,8 +217,9 @@ main() { fi if [ ! -f "$cache_file" ] || [ $(($(date +%s) - $(stat -f%c "$cache_file"))) -ge "$RATE" ]; then - trackStatus "$PAUSE_ICON" "$PLAY_ICON" > "$cache_file" - sliceTrack "$(cat $cache_file)" "$MAX_LENGTH" > "$cache_file" + local full_track + full_track=$(trackStatus "$PAUSE_ICON" "$PLAY_ICON") + sliceTrack "$full_track" "$MAX_LENGTH" > "$cache_file" fi cat "$cache_file" From 9ebbb771bc0ba2dfd83b421aeed75997d92ae36e Mon Sep 17 00:00:00 2001 From: iberniex Date: Sat, 19 Jul 2025 19:45:39 +0300 Subject: [PATCH 5/8] chore: removing echo command --- scripts/mac-player.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/mac-player.sh b/scripts/mac-player.sh index 92419bae..4c95f1ba 100755 --- a/scripts/mac-player.sh +++ b/scripts/mac-player.sh @@ -203,7 +203,6 @@ main() { # os checker if [[ "$OSTYPE" != "darwin"* ]]; then - echo "" exit 1 fi From 40ce9b7ebe0704db4b82a6aee1726f6d1da0a580 Mon Sep 17 00:00:00 2001 From: iberniex Date: Sat, 19 Jul 2025 19:46:11 +0300 Subject: [PATCH 6/8] patch: solving the remote control feature errors --- scripts/mac-player.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/mac-player.sh b/scripts/mac-player.sh index 4c95f1ba..4d9e0bba 100755 --- a/scripts/mac-player.sh +++ b/scripts/mac-player.sh @@ -172,6 +172,7 @@ function remoteControl() { else back="osascript -e 'tell application \"$app_controlled\" to set player position to 0'" fi + toggle="osascript -e 'tell application \"$app_controlled\" to playpause'" next="osascript -e 'tell application \"$app_controlled\" to play next track'" @@ -212,11 +213,13 @@ main() { PLAY_PAUSE_BUTTON=$(get_tmux_option "@dracula-mac-player-remote-play-pause" "P") BACK_BUTTON=$(get_tmux_option "@dracula-mac-player-remote-back" "R") NEXT_BUTTON=$(get_tmux_option "@dracula-mac-player-remote-next" "N") + remoteControl "$PLAY_PAUSE_BUTTON" "$BACK_BUTTON" "$NEXT_BUTTON" "$REMOTE_APP" fi if [ ! -f "$cache_file" ] || [ $(($(date +%s) - $(stat -f%c "$cache_file"))) -ge "$RATE" ]; then local full_track + full_track=$(trackStatus "$PAUSE_ICON" "$PLAY_ICON") sliceTrack "$full_track" "$MAX_LENGTH" > "$cache_file" fi From fe7ec70ea959f2fcc17b1996e9057192143e1248 Mon Sep 17 00:00:00 2001 From: iberniex Date: Sat, 19 Jul 2025 20:14:37 +0300 Subject: [PATCH 7/8] fix: clean up when remote flag is set to false --- scripts/mac-player.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/scripts/mac-player.sh b/scripts/mac-player.sh index 4d9e0bba..b70ea6f9 100755 --- a/scripts/mac-player.sh +++ b/scripts/mac-player.sh @@ -215,6 +215,14 @@ main() { NEXT_BUTTON=$(get_tmux_option "@dracula-mac-player-remote-next" "N") remoteControl "$PLAY_PAUSE_BUTTON" "$BACK_BUTTON" "$NEXT_BUTTON" "$REMOTE_APP" + else + # Clean up when remote is disabled + tmux set -g @dracula-mac-player-remote-play-pause "" + tmux set -g @dracula-mac-player-remote-back "" + tmux set -g @dracula-mac-player-remote-next "" + tmux unbind-key "$PLAY_PAUSE_BUTTON" 2>/dev/null + tmux unbind-key "$BACK_BUTTON" 2>/dev/null + tmux unbind-key "$NEXT_BUTTON" 2>/dev/null fi if [ ! -f "$cache_file" ] || [ $(($(date +%s) - $(stat -f%c "$cache_file"))) -ge "$RATE" ]; then From d640a18fe6f171a414797fe4a96b74475f549a54 Mon Sep 17 00:00:00 2001 From: iberniex Date: Sat, 19 Jul 2025 20:18:06 +0300 Subject: [PATCH 8/8] fix: coderabbit suggestions --- scripts/mac-player.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/mac-player.sh b/scripts/mac-player.sh index b70ea6f9..caba4ed1 100755 --- a/scripts/mac-player.sh +++ b/scripts/mac-player.sh @@ -160,17 +160,17 @@ function sliceTrack() function remoteControl() { - toggle_button="$1" - back_button="$2" - next_button="$3" - app_controlled="$4" + local toggle_button="$1" + local back_button="$2" + local next_button="$3" + local app_controlled="$4" if [[ $app_controlled == "Spotify" ]] || [[ $app_controlled == "Music" ]]; then if [[ $app_controlled == "Music" ]]; then back="osascript -e 'tell application \"$app_controlled\" to back track'" else - back="osascript -e 'tell application \"$app_controlled\" to set player position to 0'" + back="osascript -e 'tell application \"$app_controlled\" to previous track'" fi toggle="osascript -e 'tell application \"$app_controlled\" to playpause'"