Skip to content

Instantly share code, notes, and snippets.

@bastianccm
Created April 11, 2016 15:03
Show Gist options
  • Save bastianccm/9a86e3ec48f158700074600dd28cfaf5 to your computer and use it in GitHub Desktop.
Save bastianccm/9a86e3ec48f158700074600dd28cfaf5 to your computer and use it in GitHub Desktop.
set oldId to ""
repeat
set currentId to getTrackId()
if oldId is not currentId then
displayNotification()
end if
set oldId to currentId
write_to_file(getTrackName() & ":" & getTrackPosition(), (path to desktop as text) & getTrackArtistAlbumFilename(), false)
delay 1
end repeat
on getTrackId()
tell application "Spotify"
return id of current track
end tell
end getTrackId
on getTrackName()
tell application "Spotify"
return name of current track
end tell
end getTrackName
on getTrackArtistAlbum()
tell application "Spotify"
set alb to album of current track as string
set art to artist of current track as string
return alb & " / " & art
end tell
end getTrackArtistAlbum
on getTrackArtistAlbumFilename()
tell application "Spotify"
set alb to album of current track as string
set art to artist of current track as string
return "SpotifyLogs:" & art & "_" & alb & ".txt"
end tell
end getTrackArtistAlbumFilename
on getTrackPosition()
tell application "Spotify"
return player position
end tell
end getTrackPosition
on displayNotification()
display notification getTrackArtistAlbum() with title getTrackName()
end displayNotification
on write_to_file(this_data, target_file, append_data) -- (string, file path as string, boolean)
try
set the target_file to the target_file as text
set the open_target_file to ¬
open for access file target_file with write permission
if append_data is false then ¬
set eof of the open_target_file to 0
write this_data to the open_target_file starting at eof
close access the open_target_file
return true
on error
try
close access file target_file
end try
return false
end try
end write_to_file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment