title: Applescript to cause iTunes to play an album by Apple Music URL?
body: <p>I'm attempting to script iTunes to play an arbitrary playlist or an arbitrary album from a shell script.</p>
  
  <p>I've solved the playlist problem with the following:</p>
  
  <pre><code>osascript -e 'tell application "iTunes" to open location "'$url'?cmd=AddStation"'
  </code></pre>
  
  <p>Where url is an itmss:// type URL to a playlist. Without the "cmd=AddStation" parameter, it won't automatically play.</p>
  
  <p>This doesn't work for an album URL, however. If I execute:</p>
  
  <pre><code>osascript -e 'tell application "iTunes" to open location "'$url'"'
  </code></pre>
  
  <p>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.</p>
  
  <p>There was a similar question about a year back here <a href="https://stackoverflow.com/questions/49647648/applescript-play-music-from-itunes-url">Applescript play music from iTunes URL</a> ; 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?</p>