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

时间:2015-07-02 12:21:35

标签: applescript

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

4 个答案:

答案 0 :(得分:2)

试试这段代码。 iTunes必须处于窗口模式才能使GUI脚本无法正常工作。基本的想法是:告诉iTunes激活,检查“无线电”选项卡,当它出现时,单击它,然后为Beats 1无线电的“立即收听”按钮执行相同的操作:

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

答案 1 :(得分:1)

Rather than try and traverse the iTunes GUI, use Safari and AppleScript to launch iTunes and play Beats 1. The trick is to use Apple's Beats web page at https://itunes.apple.com/us/station/listen-in-apple-music/idra.978194965.

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

Note: For this to work, you will need to enable Allow JavaScript from Apple Events in Safari's Develop menu.

This helped: http://www.cubemg.com/how-to-click-a-button-on-a-web-page-with-applescript/

答案 2 :(得分:1)

我查看了在iTunes中启动Beats One的网页,并找到了点击该按钮时启动的网址。我现在可以使用单行AppleScript启动Beats One:

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

答案 3 :(得分:0)

我想这个查询已经解决了,无论如何我给出了适度的解决方案: 我使用Alfred,虽然automator是相同的。 我在这里创建了一个" alt + Ienter图像描述"热键打开从iTunes复制的网址。

http://imgur.com/a/VmUdd