• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

5. AppleScript for iTunes > 89. See What Other People Are Listening to

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
	set AppleScript's text item delimiters to "/"
	set fnom to (text item -1 of song_string)


	set artist to (text item -3 of song_string)
	
	set AppleScript's text item delimiters to "."
	set fnom to (text item -2 of fnom)

	set song_string to ("." & fnom & " by " & artist)

	set AppleScript's text item delimiters to ""
	if song_string's length is greater than 60 then

	  set song_string to text 1 thru 60 of song_string & "…"
    end if
	return song_string
  end extract_data_from

  to parse_file(thePath)
    return (do shell script "grep '>Music Folder<' " & ¬
      (quoted form of POSIX path of thePath) & ¬
	  " | cut -d/ -f5- | cut -d\\< -f1 | sed 's/%20/ /g'")
  end parse_file

  on replace_chars(txt, srch, repl)
    set saveD to AppleScript's text item delimiters
	set AppleScript's text item delimiters to the srch
	set the item_list to every text item of txt
	set AppleScript's text item delimiters to the repl
	set txt to the item_list as string
	set AppleScript's text item delimiters to saveD
	return txt
  end replace_chars

  on text_to_list(txt, delim)
    set saveD to AppleScript's text item delimiters
	try
      set AppleScript's text item delimiters to {delim}
	  set theList to every text item of txt
    on error errStr number errNum
      set AppleScript's text item delimiters to saveD
	  error errStr number errNum
    end try
	set ....

PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint