How to set iTunes 11 in shuffle or repeat mode via applescript

user113101 picture user113101 · Feb 3, 2013 · Viewed 7.8k times · Source

According to http://dougscripts.com/ setting shuffle and repeat modes via applescript is broken in iTunes 11.

According to this stackoverflow answer shuffle is now a playlist independent setting.

Thus, I tried to set the shuffle value via the UI, either by the LCD-ish display of iTunes or via the menu bar. All I could get was "unknown UI index" errors when trying to click the shuffle button/menu item, either in the LCD area or the menu bar. (I'm new to applescript).

If some of you could come up with a way to toggle shuffle mode on iTunes 11, that would be great. Also I'd prefer a solution based on the menu bar rather than the LCD display since the shuffle button is not always visible in the latter.

Ideally, I'd prefer a semantic-based solution over a UI-based solution but I'm not sure if it's possible (iTunes 11 applescript library seems to be outdate since it mention a "shuffle" property for "playlists" items).

Answer

ace973 picture ace973 · May 12, 2017

For the new Music app, this works. If you're using iTunes still, change "Music" to "iTunes".

Repeat can be set to one or off or all.

tell application "Music"
   set song repeat to off
end

Shuffle can be set to true or false.

tell application "Music"
   set shuffle enabled to true
end

You can find more details at Dougscripts.