set search_artist to "Orbital"
set found to {}
set shared to false
activate application "iTunes"
tell application "System Events"
tell process "iTunes"
repeat with the_row in every row of outline 1 of scroll area 1 of splitter group 1 of splitter group 1 of window 1
-- figure out the name
set the_name to value of static text 1 of the_row
-- the menu we look for to switch off connecting
-- (localised?)
if (the_name is "PLAYLISTS") then
set shared to false
end if
if shared then
-- for some reason we have to show the context menu
perform action "AXShowMenu" of the_row
-- and then dismiss it
key code {49}
end if
-- the menu we look for to switch on connecting
if the_name = "SHARED" then
set shared to true
log "Got shared"
end if
end repeat
end tell
end tell
-- for now I have this in, so we wait to connect to the shared libraries
-- would be nicer to loop over the libraries, and if they're empty (no library playlist?) wait then redo that library only
delay 30
tell application "iTunes"
repeat with theSource in every source
if kind of theSource as text is "shared library" then
set theLibrary to library playlist 1 of theSource
set theCount to count (every track of theLibrary whose artist is search_artist)
if (theCount > 0) then
set plural to "s"
if (theCount ≠ 1) then
plural = ""
end if
set the end of found to "found " & theCount & " track" & plural & " by " & search_artist & " in the shared library '" & (name of theLibrary) & "'"
end if
end if
end repeat
end tell
found