I figured this out some time ago, (I suppose I managed to google up the code or something).
tell application "iTunes"
try
if (get current stream title) is not missing value then
set lastSong to current stream title
end if
end try
end tell
tell application "iTunes"
repeat until current stream title is not equal to lastSong
delay 1
end repeat
stop
tell me to quit
end tell
I'm a novice to programming, so if there is a better way to code, please let me know.
EDIT: My code is probably based on Doug Adams' This is The Last Song and Just Play This One scripts. If/when I find the time I'll see if I can combine our code together to make scripts that work on everything.