See What Other People Are Listening to

Monitor which of your shared iTunes audio files are being played by other machines on your network.

Which of your shared songs are being listened to by other users on the network right now? Run this hack and get the lowdown.

The Code

This script locates your designated Music folder and uses the Unix command lsofto list and display the names of files in it that are open. Open files will be the ones that are being accessed by other machines.

  -- locate Music folder
  set xmlFile to "iTunes:iTunes Music Library.xml"
  set musicFolder to ""
  try
    set musicFolder to ¬
	  parse_file((path to music folder as string) & ¬
        xmlFile) as string
  end try
  if musicFolder is "" then ¬
    set musicFolder to ¬
      parse_file((path to documents folder as string) & xmlFile)

  -- get open files in Music folder
  set song_list to paragraphs of ¬
    (do shell script "readout= lsof +D " & ¬
      (musicFolder as string) & ¬
      " | grep [mp3, m4p, m4a]; echo -n $readout;")

  -- format list of shared files for display
  try
    repeat with i from 1 to (count of song_list)
      set item i of song_list to ¬
        extract_data_from(item i of song_list)
    end repeat
  on error m
    display dialog "No songs being shared right now." buttons ¬
      {"Cancel"} default button 1
  end try

  -- display shared songs
  choose from list song_list with prompt ¬ "Currently sharing:" with empty selection allowed on extract_data_from(song_string) log song_string ...

Get iPod and iTunes Hacks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.