Where you will see that it's defined only for application to a single track
(not for sequential application over a list, or over a compound reference to a set of tracks)
An easier approach might be to make a Music.app "playlist" of all the tracks which are to be heard in sequence, and then use the Keyboard Maestro Play Playlist action, applying it to the (exactly spelled) name of your playlist.
Creation of a new named playlist for all tracks with a given album string could be automated in AppleScript.
(As could its deletion, if you wanted the playlist to be temporary)
Perhaps roughly this kind of thing ?
Expand disclosure triangle to view AppleScript Source
tell application "Music"
set albumName to "Never Let You Go"
set playListName to "temporary"
set refTracks to (a reference to (tracks where album = albumName))
set nTracks to count of refTracks
if 0 < nTracks then
if exists (playlist playListName) then
set refPlayList to playlist playListName
else
set refPlayList to (make new playlist with properties {name:playListName})
end if
duplicate refTracks to end of refPlayList
("Added " & nTracks as text) & " tracks to playlist: " & playListName
else
"No tracks found with album name: " & albumName
end if
end tell
Not a proper shuffle, but you could play random tracks -- this version is "sort of random" in that it won't play the same track twice in a row:
tell application "Music"
set theTracks to every track whose album is "Back In Black"
set thisTrack to 0
repeat 10 times
set lastTrack to thisTrack
repeat until thisTrack ≠ lastTrack
set thisTrack to (get random number from 1 to (length of theTracks))
end repeat
play item thisTrack of theTracks with once
repeat while player state is playing
delay 1
end repeat
end repeat
end tell
Plays 10 random tracks from an album named in the 2nd line -- change the name and the repeat 10 times to whatever suits. Not fully tested because my test machine is 10.14 and iTunes doesn't honour the with once option...
tell application "Music"
set song repeat to off
set shuffle enabled to true
play (every track of playlist "All Files" whose album is "Never Let Me Go")
end tell
Does that work? The iTunes dictionary I looked at had it marked as "obsolete" so I didn't suggest it for the more recent Music (I know... I should know better than to trust the docs without trying for myself!).
That's the problem I've always had with my older versions of iTunes/Music. But the script above works with every version I've tried -- does it not work for you?
Rather than beat a dead digital horse, I will recommend an alternative solution that works in my tests.
Using a playlist should work around whatever issue is causing issues on your end.
Make a playlist of your Album. In my sample script, my playlist is named: Tool—10,000 Days.
The tested script:
tell application "Music"
stop
set song repeat to off
set shuffle enabled to true
play playlist "Tool—10,000 Days"
end tell
I hope that helps!
If you don't want to make a playlist yourself, then ComplexPoint's script should work (you will have to set the album name in the script):
tell application "Music"
stop
set song repeat to off
set shuffle enabled to true
set albumName to "The Downward Spiral"
set playListName to "temporary"
delete tracks of playlist playListName
set refTracks to (a reference to (tracks where album = albumName))
set nTracks to count of refTracks
if 0 < nTracks then
if exists (playlist playListName) then
set refPlayList to playlist playListName
else
set refPlayList to (make new playlist with properties {name:playListName})
end if
duplicate refTracks to end of refPlayList
("Added " & nTracks as text) & " tracks to playlist: " & playListName
else
"No tracks found with album name: " & albumName
end if
play playlist playListName
end tell