Skip to content

Instantly share code, notes, and snippets.

@Laurent-Sarrazin
Created July 1, 2014 15:28
Show Gist options
  • Save Laurent-Sarrazin/adfe5fad1b23874dfca2 to your computer and use it in GitHub Desktop.
Save Laurent-Sarrazin/adfe5fad1b23874dfca2 to your computer and use it in GitHub Desktop.
Spotify to Hipchat (with bit.ly link)
set _string to load script alias ((path to desktop as text) & "_string.scpt")
tell application "Spotify"
set current_track to null
set current_artist to null
set current_album to null
set current_track_url to null
set current_track_spotify_url 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 current_track_spotify_url to spotify url of current track
set AppleScript's text item delimiters to ":"
set current_track_url to "http://open.spotify.com/track/" & text item 3 of current_track_spotify_url
tell application "JSON Helper"
set myRecord to fetch JSON from ("https://api-ssl.bitly.com/v3/shorten?access_token=%TOKEN%&longUrl=" & current_track_url)
set myNewUrl to |url| of |data| of myRecord
end tell
set message to current_artist & " - " & current_track & " (" & myNewUrl & ")"
set message to _string's replaceString(message, "'", " ")
do shell script "curl -d '{\"color\":\"green\",\"notify\":false,\"message\":\"" & message & " !\",\"message_format\":\"text\"}' -H \"Content-Type: application/json\" https://api.hipchat.com/v2/room/Now%20playing/notification?auth_token=%AUTH_TOKEN%"
end if
delay 5
end repeat
end tell
@Nyalab
Copy link

Nyalab commented Jul 1, 2014

set _string to load script alias ((path to desktop as text) & "_string.scpt")
tell application "Spotify"
    set {current_track, current_artist, current_album, current_track_url, current_track_spotify_url} to {null, null, null, null, null}
    repeat until application "Spotify" is not running
        set {track_name, track_artist, track_album} to {name, artist, album} of current track
        if track_name ≠ current_track then
            set {current_track, current_artist, current_album, current_track_spotify_url} to {name, artist, album, spotify url} of current track
            set AppleScript's text item delimiters to ":"
            set current_track_url to "http://open.spotify.com/track/" & text item 3 of current_track_spotify_url
            set message to current_artist & " - " & current_track & " (" & current_track_url & ")"
            set message to _string's replaceString(message, "'", " ")
            do shell script "curl -d '{\"color\":\"green\",\"notify\":false,\"message\":\"" & message & " !\",\"message_format\":\"text\"}' -H \"Content-Type: application/json\" https://api.hipchat.com/v2/room/Now%20playing/notification?auth_token=t33JpGlUU7WUyqkzryMiHgk9IvdoWr68bM62RQgy"
        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