barelyknown barelyknown - 1 month ago 13
AppleScript Question

How can I open an iTunes radio station like Beats 1 with AppleScript?

There does not appear to be a direct way to open an iTunes radio station like Beats 1 with AppleScript? Is there one that I'm missing? Is there a workaround? I'm using iTunes 12.2.

Answer

Try this code. iTunes must be in windowed mode for GUI scripting to work unfortunately. The basic idea is: tell iTunes to activate, check for the "radio" tab, when it appears, click on it, then do the same thing for the "Listen Now" button for Beats 1 radio:

tell application "iTunes" to activate
tell application "System Events"
    tell window 1 of application process "iTunes"
        repeat while (radio button "Radio" of radio group 2 exists) is false
            delay 0.5
        end repeat
        click radio button "Radio" of radio group 2
        repeat while (button "Listen Now" of group 2 of group 1 of group 1 of UI element 1 of scroll area 2 exists) is false
            delay 0.5
        end repeat
        click button "Listen Now" of group 2 of group 1 of group 1 of UI element 1 of scroll area 2
    end tell
end tell
Comments