如何使用 AppleScript 打开像 Beats 1 这样的 iTunes 广播电台?

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

似乎没有直接的方法可以使用 AppleScript 打开像 Beats 1 这样的 iTunes 广播电台?有没有我想念的?有解决方法吗?我正在使用 iTunes 12.2。

试试这个代码。不幸的是,iTunes 必须处于窗口模式才能使 GUI 脚本运行。基本思路是:告诉 iTunes 激活,检查 "radio" 选项卡,当它出现时,单击它,然后对 Beats 1 收音机的 "Listen Now" 按钮执行相同的操作:

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

我想这个查询无论如何都解决了我给出了我的适度解决方案: 我使用 Alfred,虽然 automator 是一样的。 我创建了一个 "alt + Ienter image description here " 热键来打开从 iTunes 复制的 url。

http://imgur.com/a/VmUdd

与其尝试遍历 iTunes GUI,不如使用 Safari 和 AppleScript 启动 iTunes 并播放 Beats 1。诀窍是使用位于 https://itunes.apple.com/us/station/listen-in-apple-music/idra.978194965 的 Apple 的 Beats 网页。

set theClassName to "action listen-in-itunes"
set elementNum to 0

tell application "Safari"
    open location "https://itunes.apple.com/us/station/listen-in-apple-music/idra.978194965"
    do JavaScript "document.getElementsByClassName('" & theClassName & "')[" & elementNum & "].click();" in document 1
end tell

注意:为此,您需要在 Safari 的“开发”菜单中的“Apple 事件”中启用“允许”[=1​​9=]。

这有帮助:http://www.cubemg.com/how-to-click-a-button-on-a-web-page-with-applescript/

我查看了在 iTunes 中启动 Beats One 的网页,发现 URL 在单击按钮时启动。我现在可以使用 one-liner AppleScript 启动 Beats One:

open location "itmss://itunes.apple.com/us/station/listen-in-apple-music/idra.978194965?cmd=AddStation"