【问题标题】:How to select speakers for iTunes from applescript如何从 applescript 为 iTunes 选择扬声器
【发布时间】:2012-11-12 22:19:09
【问题描述】:

我希望能够从脚本中为 iTunes 选择输出声音设备(实际上任何编程语言都可以)。

目前,我能够使用 UI 元素脚本来点击按钮,该按钮提供了选择扬声器的菜单:

tell application "System Events"
     tell window "iTunes" of process "iTunes"
        set chbtn to first UI element whose help is "Choose which speakers to use."
        tell chbtn
            click
            -- tell menu 1 to get every menu item
        end tell
     end tell
end tell

这行得通,并出现带有可能选择的菜单。但是,applescript 似乎在 click 命令之后停止,并且只有在我自己单击屏幕上的某个位置后才会发生进一步的操作(在代码中注释所在的位置)。如何防止这种情况并继续从此菜单中选择菜单项?

也非常欢迎任何不恢复到 UI 脚本的解决方案!

【问题讨论】:

    标签: applescript itunes


    【解决方案1】:

    我之前在使用 UI 脚本时遇到过延迟问题。您可以通过告诉脚本单击哪些元素来消除它。我没有外部扬声器,因此元素的名称和属性不在我的计算机上。获取有关可用元素的更多信息的一种简单方法是使用(不是免费的,但非常棒的)UI Browser http://pfiddlesoft.com/uibrowser/。获取有关元素的更多信息的一种不太简单但免费的方法是使用:

    tell application "System Events"
        tell window "iTunes" of process "iTunes"
            set chbtn to first UI element whose help is "Show or hide item artwork and video viewer."
            tell chbtn
                entire contents
            end tell
    end tell
    

    说完

    【讨论】:

    • 谢谢你,一个非常好的提示“全部内容”。但这并没有太大帮助——列表是空的。菜单似乎仅在单击发生后才出现。在其他时间它不存在。不知何故,即使它存在,我也无法找到菜单所属的位置(它甚至不在进程“iTunes”的全部内容中)。此外,延迟在单击按钮后立即发生,与下一个命令无关。
    【解决方案2】:

    解决方案代码是

    tell application "iTunes" to activate
    tell application "System Events"
        tell window "iTunes" of process "iTunes"
            click (first UI element whose help is "Choose which speakers to use.")
            keystroke "DENON" & return -- Select "DENON" airplay entry
            -- keystroke "Computer" & return -- Select standard output
         end tell
    end tell
    

    但是,clickkeystroke 之间存在令人讨厌的 4 秒延迟

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-08
      相关资源
      最近更新 更多