Guest User

Untitled

a guest
Oct 17th, 2017
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ### Controls ####
  2. # play
  3. # pause or stop
  4. # mute (will toggle from mute to unmuted)
  5. # unmute
  6. # next
  7. # prev
  8. # quit, end, kill
  9. # start or init
  10. # now or current (Growl Alert)
  11. # i (Growl Alert - with an option from below)
  12. # -- artist
  13. # -- album
  14. # -- disc
  15. # -- duration or time
  16. # -- count or plays
  17. # -- track
  18. # -- starred
  19. # -- popularity or rank
  20. # -- id
  21. # -- name or song
  22. # -- album_artist
  23. # -- url
  24. ################################
  25. # Pause Example: spot pause
  26. # Change Volume: spot 75
  27. # Mute: spot mute
  28. # Unmute: spot mute || spot unmute
  29. # Start App: spot start
  30. # Kill App: spot kill
  31. # Current Track: spot current || spot now
  32. # Track Info: spot i duration || spot i id || spot i OPTION
  33. ### END ####
  34.  
  35. on sendMsg(nm, t, d, art)
  36.     tell application "GrowlHelperApp"
  37.         set the allNotificationsList to {nm}
  38.         set the enabledNotificationsList to {nm}
  39.         register as application "Spotify" all notifications allNotificationsList default notifications enabledNotificationsList icon of application "Spotify"
  40.         notify with name nm title t description d application name "Spotify" image art
  41.     end tell
  42. end sendMsg
  43.  
  44. to splitString(aString, delimiter)
  45.     set retVal to {}
  46.     set prevDelimiter to AppleScript's text item delimiters
  47.     log delimiter
  48.     set AppleScript's text item delimiters to {delimiter}
  49.     set retVal to every text item of aString
  50.     set AppleScript's text item delimiters to prevDelimiter
  51.     return retVal
  52. end splitString
  53.  
  54. to calcTime(t)
  55.     set m to (t div 60 as string)
  56.     set s to t mod 60
  57.    
  58.     if s is less than 10 then
  59.         set s to "0" & (s as string)
  60.     else
  61.         set s to (s as string)
  62.     end if
  63.    
  64.     return m & ":" & s
  65. end calcTime
  66.  
  67. on alfred_script(ctrl)
  68.    
  69.     set notify_name to ""
  70.     set notify_title to ""
  71.     set notify_desc to ""
  72.     set notify_art to ""
  73.     set tmp to my splitString(ctrl, " ")
  74.     try
  75.         set opt to item 2 of tmp
  76.     on error
  77.         set opt to "blank"
  78.     end try
  79.    
  80.     tell application "Spotify"
  81.         if ctrl is equal to "play" or ctrl is equal to "pause" then
  82.             playpause
  83.         else if ctrl is equal to "stop" then
  84.             pause
  85.         else if ctrl is equal to "next" then
  86.             next track
  87.         else if ctrl is equal to "prev" then
  88.             previous track
  89.         else if ctrl is equal to "mute" then
  90.             if sound volume is less than or equal to 0 then
  91.                 set sound volume to 100
  92.             else
  93.                 set sound volume to 0
  94.             end if
  95.         else if ctrl is equal to "quit" or ctrl is equal to "kill" or ctrl is equal to "end" then
  96.             quit
  97.         else if ctrl is equal to "start" or ctrl is equal to "init" then
  98.             activate
  99.         else if ctrl is equal to "now" or ctrl is equal to "current" then
  100.             set notify_art to artwork of current track
  101.             set notify_name to "Track Information"
  102.             set notify_title to "Now Playing"
  103.             set notify_desc to name of current track & " (" & my calcTime(duration of current track) & ")" & "\n" & artist of current track & "\n" & album of current track
  104.            
  105.         else if ctrl starts with "i" then
  106.             set notify_art to artwork of current track
  107.             set notify_name to "Track Information"
  108.            
  109.             if opt is equal to "artist" then
  110.                 set notify_title to "Artist Name"
  111.                 set notify_desc to artist of current track
  112.                
  113.             else if opt is equal to "album" then
  114.                 set notify_title to "Album Name"
  115.                 set notify_desc to album of current track
  116.                
  117.             else if opt is equal to "disc" then
  118.                 set notify_title to "Disc Number"
  119.                 set notify_desc to (disc number of current track as string)
  120.                
  121.             else if opt is equal to "duration" or opt is equal to "time" then
  122.                 set notify_title to "Duration"
  123.                 set notify_desc to my calcTime(duration of current track)
  124.                
  125.             else if opt is equal to "count" or opt is equal to "plays" then
  126.                 set notify_title to "Play Count"
  127.                 set notify_desc to (played count of current track as string)
  128.                
  129.             else if opt is equal to "track" then
  130.                 set notify_title to "Track Number"
  131.                 set notify_desc to (track number of current track as string)
  132.                
  133.             else if opt is equal to "starred" then
  134.                 set notify_title to "Starred"
  135.                 if starred of current track is equal to true then
  136.                     set notify_desc to "Yes"
  137.                 else
  138.                     set notify_desc to "No"
  139.                 end if
  140.                
  141.             else if opt is equal to "popularity" or opt is equal to "rank" then
  142.                 set notify_title to "Popularity"
  143.                 set notify_desc to (popularity of current track as string) & " out of 100"
  144.                
  145.             else if opt is equal to "id" then
  146.                 set notify_title to "ID"
  147.                 set notify_desc to id of current track
  148.                
  149.             else if opt is equal to "name" or opt is equal to "song" then
  150.                 set notify_title to "Track Name"
  151.                 set notify_desc to name of current track
  152.                
  153.             else if opt is equal to "album_artist" then
  154.                 set notify_title to "Album Artist"
  155.                 set notify_desc to album artist of current track
  156.                
  157.             else if opt is equal to "url" then
  158.                 set notify_title to "Spotify URL"
  159.                 set notify_desc to spotify url of current track
  160.                
  161.             end if
  162.            
  163.         else
  164.             try
  165.                 (ctrl as number) div 1
  166.                 set sound volume to ctrl
  167.             on error
  168.                 # do nothing
  169.             end try
  170.         end if
  171.     end tell
  172.    
  173.     if notify_desc is not equal to "" then
  174.         set the clipboard to notify_desc as text
  175.         sendMsg(notify_name, notify_title, notify_desc, notify_art)
  176.     end if
  177. end alfred_script
Add Comment
Please, Sign In to add comment