Simple iTunes AppleScript script examples

If you’ve never used AppleScript, here are two iTunes AppleScript examples to get you going. First, This one tells iTunes to play the playlist named “My Favorites”:

tell application "iTunes"
    play playlist "My Favorites"
end tell

That script starts playing a random song from that playlist. If you want to start by playing the first song of that playlist, this script will do the trick:

tell application "iTunes"
    play (first track of playlist "My Favorites")
end tell

Lastly, this script tells iTunes to stop playing whatever it’s playing at the moment:

tell application "iTunes"
    stop
end tell

For many more examples of how this works, see my large collection of iTunes AppleScript examples.