caleb531 / play-song

An Alfred workflow for quickly and easily playing music in the Apple Music app
MIT License
109 stars 9 forks source link

Shuffle All Songs Option #46

Closed kleinjm closed 7 years ago

kleinjm commented 7 years ago

Not much more to say than the title suggests.

caleb531 commented 7 years ago

For what it's worth, Play Song will respect your current iTunes shuffle setting when playing an artist/album/playlist. In the past, I have tried to add functionality that automatically enables/disables iTunes Shuffle for Play Song. However, doing so requires simulating menu clicks in AppleScript, which is rather unreliable. And surely, this implementation did not work for many of Play Song's non-English users who had their system languages set to something other than English. Yet, this is the only way to manipulate Shuffle settings in Play Song.

Similar to my own personal workflow, I would recommend creating a new Alfred workflow with two hotkey triggers—one for enabling shuffle, the other for disabling it. Each hotkey will run a AppleScript "Run Script" object that enables or disables Shuffle (respectively).

See my code below for an example of enabling shuffle:

tell application "System Events"
    tell process "iTunes"
        click menu item ¬
            "On" of menu 1 of menu item ¬
            "Shuffle" of menu 1 of menu bar item ¬
            "Controls" of menu bar 1
    end tell
end tell

And for disabling shuffle (only change was replacing "On" with "Off"):

tell application "System Events"
    tell process "iTunes"
        click menu item ¬
            "Off" of menu 1 of menu item ¬
            "Shuffle" of menu 1 of menu bar item ¬
            "Controls" of menu bar 1
    end tell
end tell

Caleb