Skip to content

Commit e177157

Browse files
Merge pull request dracula#355 from iberniex/mac-player
patch: spotify and apple-music backtrack conflicts with remote control and display optimizations
2 parents 3987eec + d640a18 commit e177157

File tree

1 file changed

+29
-22
lines changed

1 file changed

+29
-22
lines changed

scripts/mac-player.sh

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,20 @@ function sliceTrack()
160160

161161

162162
function remoteControl() {
163-
toggle_button="$1"
164-
back_button="$2"
165-
next_button="$3"
166-
app_controlled="$4"
163+
local toggle_button="$1"
164+
local back_button="$2"
165+
local next_button="$3"
166+
local app_controlled="$4"
167167

168168
if [[ $app_controlled == "Spotify" ]] || [[ $app_controlled == "Music" ]]; then
169169

170+
if [[ $app_controlled == "Music" ]]; then
171+
back="osascript -e 'tell application \"$app_controlled\" to back track'"
172+
else
173+
back="osascript -e 'tell application \"$app_controlled\" to previous track'"
174+
fi
175+
170176
toggle="osascript -e 'tell application \"$app_controlled\" to playpause'"
171-
back="osascript -e 'tell application \"$app_controlled\" to back track'"
172177
next="osascript -e 'tell application \"$app_controlled\" to play next track'"
173178

174179
tmux unbind-key "$toggle_button"
@@ -178,10 +183,6 @@ function remoteControl() {
178183
tmux bind-key "$toggle_button" run-shell "$toggle"
179184
tmux bind-key "$back_button" run-shell "$back"
180185
tmux bind-key "$next_button" run-shell "$next"
181-
else
182-
tmux unbind-key "$toggle_button"
183-
tmux unbind-key "$back_button"
184-
tmux unbind-key "$next_button"
185186
fi
186187
}
187188

@@ -198,31 +199,37 @@ main() {
198199
MAX_LENGTH=$(get_tmux_option "@dracula-mac-player-length" 25)
199200

200201
# Remote variables
201-
REMOTE_ACCESS=$(get_tmux_option "@dracula-mac-player-remote" false)
202+
REMOTE_ACCESS=$(get_tmux_option "@dracula-mac-player-remote" "false")
202203
REMOTE_APP=$(get_tmux_option "@dracula-mac-player-app" "Spotify")
203204

204-
# Remote Control Buttons Customizations
205-
PLAY_PAUSE_BUTTON=$(get_tmux_option "@dracula-mac-player-remote-play-pause" "P")
206-
BACK_BUTTON=$(get_tmux_option "@dracula-mac-player-remote-back" "R")
207-
NEXT_BUTTON=$(get_tmux_option "@dracula-mac-player-remote-next" "N")
208-
209-
210-
211205
# os checker
212206
if [[ "$OSTYPE" != "darwin"* ]]; then
213-
echo ""
214207
exit 1
215208
fi
216209

217210
# Remote Access
218-
if [[ "$REMOTE_ACCESS" == true ]]; then
219-
remoteControl "$PLAY_PAUSE_BUTTON" "$BACK_BUTTON" "$NEXT_BUTTON" "$REMOTE_APP"
211+
if [[ "$REMOTE_ACCESS" == "true" ]]; then
212+
# Remote Control Buttons Customizations
213+
PLAY_PAUSE_BUTTON=$(get_tmux_option "@dracula-mac-player-remote-play-pause" "P")
214+
BACK_BUTTON=$(get_tmux_option "@dracula-mac-player-remote-back" "R")
215+
NEXT_BUTTON=$(get_tmux_option "@dracula-mac-player-remote-next" "N")
220216

217+
remoteControl "$PLAY_PAUSE_BUTTON" "$BACK_BUTTON" "$NEXT_BUTTON" "$REMOTE_APP"
218+
else
219+
# Clean up when remote is disabled
220+
tmux set -g @dracula-mac-player-remote-play-pause ""
221+
tmux set -g @dracula-mac-player-remote-back ""
222+
tmux set -g @dracula-mac-player-remote-next ""
223+
tmux unbind-key "$PLAY_PAUSE_BUTTON" 2>/dev/null
224+
tmux unbind-key "$BACK_BUTTON" 2>/dev/null
225+
tmux unbind-key "$NEXT_BUTTON" 2>/dev/null
221226
fi
222227

223228
if [ ! -f "$cache_file" ] || [ $(($(date +%s) - $(stat -f%c "$cache_file"))) -ge "$RATE" ]; then
224-
trackStatus "$PAUSE_ICON" "$PLAY_ICON" > "$cache_file"
225-
sliceTrack "$(cat $cache_file)" "$MAX_LENGTH" > "$cache_file"
229+
local full_track
230+
231+
full_track=$(trackStatus "$PAUSE_ICON" "$PLAY_ICON")
232+
sliceTrack "$full_track" "$MAX_LENGTH" > "$cache_file"
226233
fi
227234

228235
cat "$cache_file"

0 commit comments

Comments
 (0)