For my apps type and play feature you type part or all of a song name hit enter and it plays the song if there i only 1 result and brings up all results in a list if there is more. The weird thing is, if you choose the first item in the list it gives an error, otherwise it works properly.
Here’s the code:
on titlesearch()
set songTitle to content of text field "titlesearch" of drawer "searchdrawer" of window "main"
set playTrack to ""
tell application "iTunes"
set fixedIndexing to fixed indexing
set fixed indexing to true
repeat while playTrack is ""
tell (tracks of (first playlist whose special kind is Music) whose name contains songTitle) to if (count) > 1 then
set playTrack to my chooseTracks(name, artist, album, it)
else if it is not {} then
set playTrack to item 1 of it
else
try
tell me to set songTitle to text returned of (display dialog "Your search turned up 0 results. Try again?." default answer "" buttons {"Cancel", "Go"} default button 2)
on error -- user canceled
set playTrack to false
end try
end if
end repeat
end tell
if playTrack is not false then
tell application "iTunes"
if (get version) as string < "7.1" then
set Master_Playlist to library playlist 1
else
set Master_Playlist to first playlist whose special kind is Music
end if
set view of browser window 1 to Master_Playlist
play playTrack
set fixed indexing to fixedIndexing
end tell
end if
end titlesearch
and the error if you choose the first item:
Can't get item 0 of {file track id 2112 of user playlist id 2052 of source id 46 of application "iTunes", file track id 2188 of user playlist id 2052 of source id 46 of application "iTunes", file track id 2195 of user playlist id 2052 of source id 46 of application "iTunes", file track id 2204 of user playlist id 2052 of source id 46 of application "iTunes", file track id 2281 of user playlist id 2052 of source id 46 of application "iTunes", file track id 2340 of user playlist id 2052 of source id 46 of application "iTunes", file track id 2377 of user playlist id 2052 of source id 46 of application "iTunes", file track id 2406 of user playlist id 2052 of source id 46 of application "iTunes", file track id 2423 of user playlist id 2052 of source id 46 of application "iTunes", file track id 2438 of user playlist id 2052 of source id 46 of application "iTunes", file track id 2445 of user playlist id 2052 of source id 46 of application "iTunes", file track id 2475 of user playlist id 2052 of source id 46 of application "iTunes", file track id 2509 of user playlist id 2052 of source id 46 of application "iTunes", file track id 2561 of user playlist id 2052 of source id 46 of application "iTunes"}. (-1728)
EDIT: oops, this should be in AS Studio/ XCode, my bad