Skip to content
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions scripts/mac-player.sh
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,13 @@ 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"
Expand All @@ -178,10 +183,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
}

Expand All @@ -198,31 +199,29 @@ 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 ""
exit 1
fi

# Remote Access
if [[ "$REMOTE_ACCESS" == true ]]; then
remoteControl "$PLAY_PAUSE_BUTTON" "$BACK_BUTTON" "$NEXT_BUTTON" "$REMOTE_APP"
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"
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"
Expand Down