Advertisement
Guest User

Untitled

a guest
Jul 29th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. tell application "System Events"
  2.     set num to count (every process whose name is "iTunes")
  3. end tell
  4. set maxSize to 30
  5.  
  6. if num > 0 then
  7.    
  8.     try
  9.         tell application "iTunes" to tell artwork 1 of current track
  10.             set srcBytes to raw data
  11.             -- figure out the proper file extension
  12.             if format is «class PNG » then
  13.                 set ext to ".png"
  14.             else
  15.                 set ext to ".jpg"
  16.             end if
  17.         end tell
  18.        
  19.        
  20.         set fileName to ((((path to application support folder from user domain) as text) & "BetterTouchTool:" as text) & "itunes_cover" & ext)
  21.         -- write to file
  22.         set outFile to open for access file fileName with write permission
  23.         -- truncate the file
  24.         set eof outFile to 0
  25.         -- write the image bytes to the file
  26.         write srcBytes to outFile
  27.         close access outFile
  28.     on error
  29.         set fileName to ((((path to application support folder from user domain) as text) & "BetterTouchTool:" as text) & "default.png")
  30.     end try
  31.    
  32.     tell application "iTunes"
  33.         set playState to (player state as text)
  34.         set trackName to name of current track
  35.         set artistName to artist of current track
  36.         set albumName to album of current track
  37.         if length of trackName is greater than 15 then
  38.             set trackName to text 1 thru 15 of trackName & "..."
  39.         end if
  40.         if length of artistName is greater than 15 then
  41.             set artistName to text 1 thru 15 of artistName & "..."
  42.         end if
  43.         set trackInfo to artistName & ": " & trackName
  44.        
  45.         return "{\"text\":\"" & trackInfo & "\",\"icon_path\":\"" & (POSIX path of fileName as text) & "\"}"
  46.     end tell
  47. else
  48.     return ""
  49. end if
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement