2 Scripts... 1 without creating a playlist:
this script should run best as an AppleScript application...
tell application "iTunes"
set mysongs to every track whose name contains "angel"
display dialog "now playing " & (count of mysongs) & " songs." giving up after 1
repeat with i from 1 to count of mysongs
set mysong to item i of mysongs
play mysong
##give iTunes a sec to realize current track
delay 1
repeat until mysong ≠current track
#delay otherwhise cpu load is very high
delay 0.25
end repeat
stop
end repeat
end tell
to create a real playlist is better anyway, because the script does not have to run all time:
2. Solution with creating a playlist first:
tell application "iTunes"
set mysongs to every track whose name contains "ever"
-- display dialog "now playing " & (count of mysongs) & " songs." giving up after 1
set playlistname to "PLAY_THIS"
try
get playlist playlistname of source 1 as reference
on error
tell source 1
make new playlist with properties {name:playlistname}
end tell
end try
tell playlist playlistname of source 1
delete every track
set shuffle to false
set song repeat to off
end tell
repeat with i from 1 to count of mysongs
set mysong to item i of mysongs
set playlistsongs to {}
try
#try because of error on empty list
set playlistsongs to database ID of every track of playlist playlistname of source 1
end try
if (database ID of mysong) is not in playlistsongs then
copy mysong to playlist playlistname of source 1
end if
end repeat
tell playlist playlistname of source 1 to play
end tell