Created
July 1, 2014 15:28
-
-
Save Laurent-Sarrazin/adfe5fad1b23874dfca2 to your computer and use it in GitHub Desktop.
Spotify to Hipchat (with bit.ly link)
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
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
commented
Jul 1, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment