如何从applescript 中为iTunes 选择扬声器 [英] How to select speakers for iTunes from applescript

查看:24
本文介绍了如何从applescript 中为iTunes 选择扬声器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I would like to be able to select output sound device for iTunes from a script (any programming language would be ok in fact).

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

For the moment I was able to use UI element scripting to get up to clicking on the button which gives the menu to select the speakers:

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 命令之后停止,并且只有在我自己单击屏幕上的某个位置后才会发生进一步的操作(在代码中注释的位置).如何防止这种情况并继续从此菜单中选择菜单项?

This works, and menu with possible choices appears. However, the applescript seems to stop after the click command, and further actions (in the place where the comment is in the code) happen only after I click somewhere on the screen myself. How can I prevent this and continue to select the menu item from this menu?

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

Any solution without reverting to UI scripting is also very welcome!

推荐答案

解决方案代码为

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

这篇关于如何从applescript 中为iTunes 选择扬声器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆