Applescript studio - 如何在窗口中获取每个控件

时间:2010-03-24 00:20:59

标签: interface-builder applescript-studio

当程序从交互模式更改为非交互模式时,我正在尝试启用或禁用窗口中的所有控件。我怎么能要求窗口给我所有内容?

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)

我根据程序所处的状态制作了几个控件列表,但是它必须是硬编码的,我认为这不是最好的方式。

3 个答案:

答案 0 :(得分:2)

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

此脚本将为您提供Adium前窗的所有内容:窗口的窗口,窗口的工具栏,工具栏的按钮等。享受=]

答案 1 :(得分: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

答案 2 :(得分: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