【问题标题】:Detecting if a window is open检测窗口是否打开
【发布时间】:2018-08-02 21:04:24
【问题描述】:

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

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

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

这是我的窗口元素:

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",

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

【问题讨论】:

    标签: applescript


    【解决方案1】:

    这行有点奇怪:

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

    static text 对象通常以其包含的文本值命名。因此,我期望static text 中的value"RemoteDatabasePrefs"

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

    set Test1 to the title of window "RemoteDatabasePrefs" of ...
    

    name 属性明确设置为"RemoteDatabasePrefs"title 属性通常与name 相同,并且通常都匹配窗口标题栏中的文本。但是,您可能遇到过一个例外,即nametitle 属性的值不同;在这种情况下,您需要 title 属性的值,它应该与标题文本匹配。


    要测试窗口是否已关闭,您可以使用exists 命令测试window 对象是否仍然存在。当一个窗口关闭时,它就不再存在了。

    tell application "System Events to tell process "OsiriX"
        set isOpen to (exists window "RemoteDatabasePrefs")
    end tell
    

    变量isOpen 将包含一个布尔值truefalse,告诉您窗口是打开(true) 还是关闭(false)。

    【讨论】:

      猜你喜欢
      • 2021-09-16
      • 1970-01-01
      • 2012-08-18
      • 1970-01-01
      • 2013-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多