Skip to content

Instantly share code, notes, and snippets.

@josefglatz
Last active August 29, 2015 14:10
Show Gist options
  • Save josefglatz/13e2a7325e3e4ff5250e to your computer and use it in GitHub Desktop.
Save josefglatz/13e2a7325e3e4ff5250e to your computer and use it in GitHub Desktop.
Spotify to HipChat with Cover Support
-- Free JSON Helper for AppleScript is required to fetch Spotify Web API (from Apple App Store)
tell application "Spotify"
set current_track to null
set current_artist to null
set current_album to null
repeat until application "Spotify" is not running
set track_name to name of current track
set track_artist to artist of current track
set track_album to album of current track
if track_name ≠ current_track then
set current_track to name of current track
set current_artist to artist of current track
set current_album to album of current track
set track_id to id of current track
tell application "JSON Helper"
set thumbnailUrl to null
set json to fetch JSON from ("https://embed.spotify.com/oembed/?url=" & track_id & "")
set thumbnailUrl to thumbnail_url of json
set height to thumbnail_height of json
set width to thumbnail_width of json
if thumbnailUrl is not equal to "" then
set thumbnailImage to "<img src='" & thumbnailUrl & "' width='30' height='30' /> "
end if
end tell
set message to thumbnailImage & "♪ <strong>" & current_artist & "</strong> - " & current_track & " - (" & current_album & ")"
set message to do shell script "echo " & quoted form of message & " | sed 's/'\\''//g' | sed 's/'\\&'/'and'/g'"
do shell script "curl -ksS -d 'auth_token=AUTHTOKEN&room_id=5&from=USER&color=purple&message=" & message & "' https://api.hipchat.com/v1/rooms/message"
end if
delay 5
end repeat
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment