【发布时间】:2016-03-06 21:30:34
【问题描述】:
我正在尝试解决我制作的这个 Applescript 中的一个特定问题:https://gist.github.com/jwmann/08daed8a905cfbf4ff96
上下文:
这是一个 Applescript,您可以在其中选择 VLC 播放列表中的一首歌曲,运行 Applescript,它会将歌曲从原始位置删除。
问题:
当用户尝试删除当前播放的单首歌曲时,会出现问题,而 VLC 播放列表的大小仅为单首歌曲的大小。
现在,如果您尝试删除当前正在播放的歌曲,VLC 会爆炸。为了解决这个问题,我让脚本停止播放 VLC 并再次尝试删除它。
现在如果发生这种解决方法,VLC 将不再播放。在多歌曲播放列表中,这不会很烦人。所以脚本将在脚本结束时继续播放 VLC。但是,从单个歌曲播放列表中删除歌曲后,它会将歌曲从播放列表中删除,不留下任何歌曲,因此也没有播放列表。
因此,当脚本尝试播放时,它会打开一个新窗口/对话框/模式以允许用户找到要播放的内容。这是我不想发生的事情。
我想要做什么:
我需要一种方法:
- 检测正确的窗口
- 关闭该窗口
我收集的信息:
这是我要取消的窗口
这是 Accessibility Inspector 向我显示的关于窗口的数据。
<AXApplication: “VLC”>
<AXWindow: “Open Source”>
Attributes:
AXFocused: “0”
AXFullScreen: “0”
AXTitle: “Open Source”
AXPosition (W): “x=993 y=276”
AXGrowArea: “(null)”
AXMinimizeButton: “(null)”
AXDocument: “(null)”
AXSections (W): “<array of size 1>”
AXCloseButton: “(null)”
AXMain: “0”
AXFullScreenButton: “(null)”
AXProxy: “(null)”
AXDefaultButton: “<AXButton: “Open”>”
AXMinimized: “0”
AXChildren: “<array of size 8>”
AXRole: “AXWindow”
AXParent: “<AXApplication: “VLC”>”
AXTitleUIElement: “<AXStaticText>”
AXCancelButton: “<AXButton: “Cancel”>”
AXModal: “1”
AXSubrole: “AXDialog”
AXZoomButton: “(null)”
AXRoleDescription: “dialog”
AXSize: “w=574 h=402”
AXToolbarButton: “(null)”
AXFrame: “x=993 y=276 w=574 h=402”
AXIdentifier: “_NS:40”
Actions:
AXRaise - raise
我尝试过的事情:
tell application "System Events"
close window "Open Source" of application "VLC"
end tell
tell application "System Events"
click button "Cancel" of window "Open Source" of application "VLC"
end tell
tell application "System Events"
cancel window "Open Source" of application "VLC"
end tell
tell application "System Events" to tell (window 1 of application "VLC" whose subrole is "AXDialog") to close
在每个示例中,系统事件或 VLC(我都尝试过)似乎无法找到“开源”窗口,即使它在检查器中明确称为“开源”。这不是一张床单,它是一个窗口。我不明白为什么我无法找到这个窗口。
【问题讨论】:
-
您可能需要将其作为对话框引用...注意
AXSubrole,看起来您尝试了类似的东西...但可能会反转它。窗口可能不是控件所在的位置,而是窗口 1 的对话框。 -
@l'L'l 我做了
tell application "System Events" to tell (dialog of window 1 of application "VLC") to close并收到错误“VLC 出错:无法将窗口 1 的对话框转换为类型引用。” -
不幸的是,我从来没有像你尝试过的那样真正调用窗口外的对话框,所以除了我在这里看到的之外,我认为这将是一个尝试获得正确语言的问题。我知道它会变得很棘手......有一个非常好的 Applescript 调试器(你可以下载它的试用版),称为 Script Debugger——它在这种情况下真的很有帮助;所以也许值得一看。
-
谢谢@l'L'l 我使用该程序更轻松地查看数据,并在下面解决了我的问题。
标签: macos dialog modal-dialog applescript vlc