Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- tell application "System Events"
- set num to count (every process whose name is "iTunes")
- end tell
- set maxSize to 30
- if num > 0 then
- try
- tell application "iTunes" to tell artwork 1 of current track
- set srcBytes to raw data
- -- figure out the proper file extension
- if format is «class PNG » then
- set ext to ".png"
- else
- set ext to ".jpg"
- end if
- end tell
- set fileName to ((((path to application support folder from user domain) as text) & "BetterTouchTool:" as text) & "itunes_cover" & ext)
- -- write to file
- set outFile to open for access file fileName with write permission
- -- truncate the file
- set eof outFile to 0
- -- write the image bytes to the file
- write srcBytes to outFile
- close access outFile
- on error
- set fileName to ((((path to application support folder from user domain) as text) & "BetterTouchTool:" as text) & "default.png")
- end try
- tell application "iTunes"
- set playState to (player state as text)
- set trackName to name of current track
- set artistName to artist of current track
- set albumName to album of current track
- if length of trackName is greater than 15 then
- set trackName to text 1 thru 15 of trackName & "..."
- end if
- if length of artistName is greater than 15 then
- set artistName to text 1 thru 15 of artistName & "..."
- end if
- set trackInfo to artistName & ": " & trackName
- return "{\"text\":\"" & trackInfo & "\",\"icon_path\":\"" & (POSIX path of fileName as text) & "\"}"
- end tell
- else
- return ""
- end if
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement