我正在尝试自动化一些任务,这些任务需要在对话框中显示文本(6位代码)。

objective-c - 使用AppleScript获取NSTextFieldCell值-LMLPHP

辅助功能检查器显示以下层次结构:

objective-c - 使用AppleScript获取NSTextFieldCell值-LMLPHP

我是AppleScript领域的初学者,并且阅读了一些可以进行类似操作的示例:

set myText to textField's stringValue() as text


但是我不确定这是否可以解决我的问题,因为Accessibility Inspector不会显示NSTextFieldCell包含6位数字代码的任何变量名称。

如何提取NSTextFieldCell中的6位代码并可能返回此值,以便Shell脚本可以使用此代码?

我现在有这样的事情-

tell application "FollowUpUI"
    activate
    # get the 6 digit code
end tell




更新资料

寻求帮助后,我尝试遍历文本字段

tell application "System Events"

    repeat with theProcess in processes

        #initialize
        tell theProcess
            set processName to name
            set allWindows to windows
        end tell

        #check if process exists
        if processName is "FollowUpUI" then

            activate

            say "FollowUpUI found"

            set windowsCount to count of the allWindows

            #only one window should exist
            if windowsCount is 1 then
                say "1 window was found"

                tell window 1
                    tell group 1
                        tell text field 1
                            set code to value
                        end tell
                    end tell
                end tell

            end if
        end if
    end repeat
end tell


但由于错误我被卡住了-

System Events got an error: cant get window 1. Invalid index.


我不确定这是否是语法错误。任何指针都会有所帮助。谢谢

最佳答案

发生错误,因为您必须引用window 1 of process "FollowUpUI"

您的代码太复杂,您只需要检查该过程是否存在

tell application "System Events"
    if exists process "FollowUpUI" then
        tell process "FollowUpUI"
            tell window 1
                tell static text 1 of group 1
                    set code to its value
                end tell
            end tell
        end tell
    end if
end tell


如果代码是工作流程的一部分,则必须等待窗口打开

tell application "System Events"
    repeat until exists window 1 of process "FollowUpUI"
        delay 0.2
    end repeat
    tell window 1 of process "FollowUpUI"
        tell static text 1 of group 1
            set code to its value
        end tell
    end tell
end tell


我在its之前添加了value以确保它引用了当前引用(文本字段)

由于您不向窗口发送键或鼠标事件,因此不需要activate进行任何操作。

09-29 19:53