Skip to content

Instantly share code, notes, and snippets.

@gaqzi
Created October 22, 2021 00:35
Show Gist options
  • Save gaqzi/e69adaab07e9f09ad9285affcabec4d1 to your computer and use it in GitHub Desktop.
Save gaqzi/e69adaab07e9f09ad9285affcabec4d1 to your computer and use it in GitHub Desktop.
Control Spotify using AppleScript
on alfred_script(q)
tell application "Spotify"
next track
end tell
end alfred_script
on alfred_script(q)
set newline to "
"
tell application "System Events"
set MyList to (name of every process)
end tell
if (MyList contains "Spotify") is true then
tell application "Spotify"
set track_name to name of current track
set track_artist to artist of current track
set track_album to album of current track
end tell
do shell script "open \"http://genius.com/$(echo '" & quoted form of track_artist & "-" & quoted form of track_name & "' | sed -E 's|([ ]+)|-|g' | iconv -f 'utf-8' -t 'ASCII//TRANSLIT' | sed -E 's|[^a-zA-Z0-9-]||g')-lyrics\""
end if
end alfred_script
on alfred_script(q)
tell application "Spotify"
playpause
end tell
end alfred_script
on alfred_script(q)
tell application "Spotify"
previous track
end tell
end alfred_script
-- biggest indicator of how long ago it was that I wrote this,
-- I still have growl installed because I haven't bothered migrating to
-- the built-in notifications
on alfred_script(q)
set newline to "
"
tell application "System Events"
set MyList to (name of every process)
end tell
if (MyList contains "Spotify") is true then
tell application "Spotify"
set track_name to name of current track
set track_artist to artist of current track
set track_album to album of current track
end tell
tell application "Growl"
-- Make a list of the notifications this script will ever send.
set the notificationsList to {"Current Spotify Track"}
-- Register our script with Growl
-- You can optionally (as here) set a default icon
-- for this script's notifications.
register as application "Spotify Notifier Script" all notifications notificationsList default notifications notificationsList icon of application "Spotify"
set desc to track_artist & newline & track_album
notify with name "Current Spotify Track" title track_name description desc application name "Spotify Notifier Script" icon of application "Spotify.app"
end tell
end if
end alfred_script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment