Created
February 22, 2012 12:45
-
-
Save elliottkember/1884925 to your computer and use it in GitHub Desktop.
Spotify Applescript
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
property baseURL : "http://statusboard.dev/song?" | |
if application "Spotify" is running then | |
tell application "Spotify" | |
set theTrack to name of the current track | |
set theArtist to artist of the current track | |
set theAlbum to album of the current track | |
set theurl to spotify url of the current track | |
try | |
do shell script "/usr/local/bin/wget --delete-after \"" & baseURL & "&t=" & theTrack & "&a=" & theArtist & "&al=" & theAlbum & "\"" | |
on error err | |
end try | |
end tell | |
end if | |
-- Paths and stuff | |
set ArtworkFromSpotify to ((path to home folder) as text) & ¬ | |
"Sites:statusboard:public:images:albumArt1.tiff" as alias | |
set SpotifyArtwork to ((path to home folder) as text) & ¬ | |
"Sites:statusboard:public:images:albumArt1.tiff" | |
set DefaultArtwork to ((path to home folder) as text) & ¬ | |
"Sites:statusboard:public:images:albumArt.tiff" | |
set displayArtwork to ((path to home folder) as text) & ¬ | |
"Sites:statusboard:public:images:albumArt.tiff" | |
-- Unix versions of the above path strings | |
set unixSpotifyArtwork to the quoted form of POSIX path of SpotifyArtwork | |
set unixDefaultArtwork to the quoted form of POSIX path of DefaultArtwork | |
set unixDisplayArtwork to the quoted form of POSIX path of displayArtwork | |
set whichArt to "blank" | |
tell application "System Events" | |
if exists process "Spotify" then -- Spotify is running | |
tell application "Spotify" | |
if player state is playing then -- Spotify is playing | |
set aTrack to current track | |
set aTrackArtwork to null | |
set aTrackArtwork to artwork of aTrack | |
set fileRef to ¬ | |
(open for access ArtworkFromSpotify with write permission) | |
try | |
write aTrackArtwork to fileRef | |
close access fileRef | |
on error errorMsg | |
try | |
close access fileRef | |
end try | |
error errorMsg | |
end try | |
tell application "Finder" to ¬ | |
set creator type of ArtworkFromSpotify to "????" | |
set whichArt to "Spotify" | |
end if | |
end tell | |
end if | |
end tell | |
if whichArt is "Spotify" then | |
do shell script "ditto -rsrc " & unixSpotifyArtwork & space & unixDisplayArtwork | |
else | |
do shell script "ditto -rsrc " & unixDefaultArtwork & space & unixDisplayArtwork | |
end if |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment