2010-03-24 56 views
0

我试图启用或禁用窗口中的所有控件,因为程序从交互模式更改为非交互模式。我怎么能问一个窗口给我所有的内容?Applescript工作室 - 我如何获得窗口中的每个控件

every control of window "mainWindow" 

不工作,也不

contents of window "mainWindow" 

其实,我一直没能找到任何好的文档,从界面生成器的所有菜单项进行交互。比如如何设置弹出窗口和按钮等的内容。

感谢

我这样做是在目前的方法是:

property onlineControls: {"maxLength", "speed", "accelerationSlider", "accelerationField", "showInfo"} --and so on, listing all the controls by name 

on enableControls(theList, enableState) 
    tell window "mainWindow" 
     repeat with theControl in theList 
      set the enabled of control theControl to enableState 
     end repeat 
    end tell 

enableControls(onlineControls, true) 

我做的几个控制列表THT得到开启或关闭取决于程序的状态,但。它必须是硬编码的,我认为这并不是最好的方式。

回答

2
tell application "System Events" 
    tell process "Adium" 
     get entire contents of window 1 
    end tell 
end tell 

这个脚本会Adium前窗的所有内容:窗口,窗口的工具栏,工具栏的按钮等等。享受=]

+0

“全部内容”Whoda thunk它?感谢那。 – stib 2010-05-11 12:39:06

0

我一直没能找到一种方式来获得在一个窗口中的所有控件,但这里有一个弹出式菜单按钮的菜单交互的例子:

tell menu of popup button "somePopupButton" of window "mainWindow" 
    delete every menu item 
    repeat with i in someItems 
     make new menu item at end of menu items ¬ 
      with properties {title:i, enabled:true} 
    end repeat 
end tell 
+0

谢谢。不幸的是,我想让弹出按钮(以及按钮,滑块和文本字段等)被禁用,而不是其中的菜单项。 – stib 2010-03-25 10:39:17

0

与“BoB1990”具有相同的脚本,通过获取您可以观察或查看的字符串中的窗口的全部内容给出的信息修改列出的所有项目:

tell application "System Events" to tell process "Adium" 

    set this_info to {} 

    try 

    display alert ((get entire contents of window (x as integer)))  

    on error errMsg set theText to errMsg 

    set this_info to do shell script " echo " & theText & " | sed 's#System Events got an error: Can’t make ##g;s# into type string.##g'" 

    end try 

    set info to {} 

    set info to do shell script " echo " & this_info 

    display alert (info) 

    end tell 
+0

与“BoB1990”具有相同的脚本,可以通过获取窗口的全部内容获取所给信息的可能性,该字符串可以观察或修改列出的所有项目: – deek5 2016-11-07 06:56:22

相关问题