Applescript to cause iTunes to play an album by Apple Music URL?

Viewed 502

I'm attempting to script iTunes to play an arbitrary playlist or an arbitrary album from a shell script.

I've solved the playlist problem with the following:

osascript -e 'tell application "iTunes" to open location "'$url'?cmd=AddStation"'

Where url is an itmss:// type URL to a playlist. Without the "cmd=AddStation" parameter, it won't automatically play.

This doesn't work for an album URL, however. If I execute:

osascript -e 'tell application "iTunes" to open location "'$url'"'

where url is defined as an itmss:// album URL, then the album does come up on iTunes, but it won't start playing. If I tell iTunes to play via Applescript, it instead starts playing the first album in the entire iTunes library, not the album that is displayed.

There was a similar question about a year back here Applescript play music from iTunes URL ; however, the solution provided in that response requires you to know the title of the first track you want to play. Does anyone have an idea for a more generic solution that will bring an album from the command-line and then play the first track?

0 Answers
Related