Advertisement
Haulien

itunes.scpt

Dec 27th, 2011
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Copyright © 2011 Alex Sørlie
  2. -- <http://twitter.com/techie94>
  3.  
  4. on textualcmd()
  5.     set listening to "/me is not currently running iTunes"
  6.    
  7.     tell application "System Events"
  8.         tell application "System Events" to set is_running to exists (processes where name is "iTunes")
  9.     end tell
  10.    
  11.     if is_running then
  12.         tell application "iTunes"
  13.             if player state is playing then
  14.                 set listening to "/me is listening to "
  15.                
  16.                 if current stream title is not missing value then
  17.                     set listening to listening & name of current track & " streaming \""
  18.                     set {art, nom} to my text_to_list(current stream title, " - ")
  19.                     set listening to listening & art & " - " & nom & "\""
  20.                 else
  21.                     set the_kind to kind of current track
  22.                     set songsize to ((size of current track) / 1048576)
  23.                     set songsize to (round (songsize * 100)) / 100
  24.                    
  25.                     set movie_list to {"Movies", "TV Shows", "Podcasts", "iTunes U"}
  26.                     set movie_kinds to {"MP4", "Movie", "WAV"}
  27.                    
  28.                     if the_kind contains "MPEG-3 audio file" then set the_kind to "MP3"
  29.                     if the_kind contains "MPEG-4 video file" then set the_kind to "MP4"
  30.                     if the_kind contains "QuickTime movie file" then set the_kind to "Movie"
  31.                     if the_kind contains "AAC" then set the_kind to "AAC"
  32.                     if the_kind contains "WAV" then set the_kind to "WAV"
  33.                     if the_kind contains "Apple Lossless" then set the_kind to "Apple Lossless"
  34.                    
  35.                     if name of current playlist is in movie_list and the_kind is in movie_kinds then
  36.                         set iartist to artist of current track
  37.                        
  38.                         if length of iartist is 0 then
  39.                             set listening to "/me is watching " & name of current track & " [" & time of current track & " mins] [" & bit rate of current track & " kbps " & the_kind & "] [" & songsize & " MB]"
  40.                         else
  41.                             set listening to "/me is watching " & artist of current track & " - " & name of current track & " [" & time of current track & " mins] [" & bit rate of current track & " kbps " & the_kind & "] [" & songsize & " MB]"
  42.                         end if
  43.                     else
  44.                         set listening to listening & artist of current track & " - " & name of current track & ", from the album " & album of current track & ""
  45.                     end if
  46.                 end if
  47.             else
  48.                 set listening to "/me is not currently playing anything in iTunes"
  49.             end if
  50.         end tell
  51.     end if
  52.    
  53.     return listening
  54. end textualcmd
  55.  
  56. -- text_to_list AppleScript function from:
  57. -- <http://dougscripts.com/itunes/itinfo/locatemf.php>
  58. on text_to_list(txt, delim)
  59.     set saveD to AppleScript's text item delimiters
  60.     try
  61.         set AppleScript's text item delimiters to {delim}
  62.         set theList to every text item of txt
  63.     on error errStr number errNum
  64.         set AppleScript's text item delimiters to saveD
  65.         error errStr number errNum
  66.     end try
  67.     set AppleScript's text item delimiters to saveD
  68.     return (theList)
  69. end text_to_list
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement