Display iTunes songs being listened to by others

Feb 10, '04 09:32:00AM

Contributed by: hoff10000

The other day I thought to myself "Gee, I wish I could see what songs people are listening to in my iTunes shared library...", so I created this AppleScript that does just that! Taking the idea of using lsof +D path/to/music | grep {mp3,m4a,m4p} from another post, this script displays the song title and artist of each track being played locally and over a network in a dialog box. It's been tested with iTunes 4.2 in Panther 10.3.2. Enjoy!

Read the rest of the hint for the script...

--Script created by Elliott Hoffman 2004
-- Thanks to Jonn of http://homepage.mac.com/jonn8/as/ 
-- for debugging help!
-- "dir" must be set to the directory of your iTunes Music Library
set dir to "Path/to/my/iTunes/Library" as string
set shell_script to "readout= lsof +D" & " " & dir & " | ¬
 grep [mp3,m4p,m4a]; echo -n $readout;"
set song_list to paragraphs of (do shell script shell_script)
try
  set message to "Songs people are listening to:" as string
  repeat with song_list_index from 1 to (count of song_list)
    set item song_list_index of song_list to ¬
     (trim_path(item song_list_index of song_list) & ¬
     (return)) as string
    song_list_index = song_list_index + 1
  end repeat
  set message to "Songs being listened to:" & return ¬
   & song_list
  on error
  set message to ¬
   "There are no songs being listened to right now." as string
end try
display dialog ¬
message ¬
  buttons {"OK"} default button 1 with icon 1
  on trim_path(song_string)
    my set_delim("/")
    set song to (text item -1 of song_string)
    set artist to (text item -3 of song_string)
    my set_delim(".")
    set song to (text item -2 of song)
    set song_string to ("•" & song & " by " & artist)
    my set_delim("")
    if song_string's length is greater than 36 then
      set song_string to (get text 1 thru 36 of song_string) & "..."
    end if
    return song_string
  end trim_path
on set_delim(the_delim)
  set AppleScript's text item delimiters to the_delim
end set_delim
If you'd prefer to skip the typing, you can download a formatted version.

P.S.: This can be added to the iTunes scripts menu by saving the script as an Application and putting it in the ~/Library -> iTunes -> Scripts folder (you can create it if you don't have it).

Comments (7)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20040130232918873