Last active
June 5, 2019 15:00
-
-
Save LeZuse/cf1bb8065c9e08b38e963d205131bf88 to your computer and use it in GitHub Desktop.
A bash helper for controlling Spotify on Mac over osascript
This file contains 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
#!/usr/bin/env bash | |
# Install: | |
# ln -s $PWD/spotify-cmd.sh /usr/local/bin/spotify | |
ARG=$@ | |
usage () { | |
echo "Usage: $0 [play|pause|playpause|next track|previous track]" | |
} | |
command () { | |
osascript <<EOF | |
if application "Spotify" is not running then | |
tell application "Spotify" to activate | |
tell application "System Events" to tell process "Spotify" to keystroke "h" using command down | |
delay 5 | |
end | |
if application "Spotify" is running then | |
tell application "Spotify" to $1 | |
end if | |
EOF | |
} | |
if [[ "$ARG" = '' ]]; then usage; exit; fi | |
command "$ARG" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment