Skip to content

Instantly share code, notes, and snippets.

@LeZuse
Last active June 5, 2019 15:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LeZuse/cf1bb8065c9e08b38e963d205131bf88 to your computer and use it in GitHub Desktop.
Save LeZuse/cf1bb8065c9e08b38e963d205131bf88 to your computer and use it in GitHub Desktop.
A bash helper for controlling Spotify on Mac over osascript
#!/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