检测窗口是否打开

时间:2018-08-01 19:51:21

标签: applescript

如何检测我的对话框窗口是否已关闭?

  • 我打开一个对话框窗口
  • 然后我要读取窗口标题值并显示结果
  • 然后我关闭窗口
  • 然后我要检测窗口对话框是否关闭

    在DatabaseRefresher()上 menu_click({“ OsiriX”,“插件”,“数据库”,“ SetRemoteDatabaseRefresh”}) 延迟1 将Test1设置为0
    将Test1设置为应用程序“系统事件”的应用程序进程“ OsiriX”的窗口“ RemoteDatabasePrefs”的静态文本“ RemoteDatabasePrefs”的值 记录Test1 PressButton(“取消”,“ OsiriX”,“ RemoteDatabasePrefs”)-(TheButtonToPress,TheProgramName,TheWindow) 在此处添加测试以检测窗口是否关闭) 结束DatabaseRefresher

这是我的窗口元素:

button "OK" of window "RemoteDatabasePrefs" of application process "OsiriX" of application "System Events", 
button "Cancel" of window "RemoteDatabasePrefs" of application process "OsiriX" of application "System Events", 
text field 1 of window "RemoteDatabasePrefs" of application process "OsiriX" of application "System Events", 
static text "RemoteDatabasePrefs" of window "RemoteDatabasePrefs" of application process "OsiriX" of application "System Events"
static text "Enter Remote Database Refresh Interval in minutes:" of window "RemoteDatabasePrefs" of application process "OsiriX" of application "System Events", 
button 3 of window "RemoteDatabasePrefs" of application process "OsiriX" of application "System Events", 
button 4 of window "RemoteDatabasePrefs" of application process "OsiriX" of application "System Events", 
button 5 of window "RemoteDatabasePrefs" of application process "OsiriX" of application "System Events",

作为菜鸟,如果我问的是非常基本的问题,我深表歉意。我确实有一些可以使用的脚本,而且我似乎知道它们的工作方式,但是当我尝试对其进行重构时,我似乎花了太多时间寻找解决方案

1 个答案:

答案 0 :(得分:0)

这行有点奇怪:

set Test1 to value of static text "RemoteDatabasePrefs" of window "RemoteDatabasePrefs" of ...

static text对象通常以它们包含的文本值命名。因此,我会期望value的{​​{1}}为static text

但是,如果这样做是为了获取窗口的标题文本,则无需读取某些"RemoteDatabasePrefs"对象的值;您可以改为访问static text对象的name属性或title属性:

window

set Test1 to the title of window "RemoteDatabasePrefs" of ... 属性明确设置为name"RemoteDatabasePrefs"属性通常与title相同,并且通常都与窗口标题栏中的文本匹配。但是,您可能遇到了一个例外,其中namename属性的值不同;在这种情况下,您需要使用title属性的值,该值应与标题文本匹配。


要测试窗口是否已关闭,请使用title命令测试exists对象是否仍然存在。关闭窗口后,该窗口便不再存在。

window

变量tell application "System Events to tell process "OsiriX" set isOpen to (exists window "RemoteDatabasePrefs") end tell 将包含一个布尔值isOpentrue,告诉您窗口是打开(false)还是已关闭({{1} }。

相关问题