Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 使用AppleScript获取NSTextFieldCell值_Objective C_Macos_User Interface_Cocoa_Applescript - Fatal编程技术网

Objective c 使用AppleScript获取NSTextFieldCell值

Objective c 使用AppleScript获取NSTextFieldCell值,objective-c,macos,user-interface,cocoa,applescript,Objective C,Macos,User Interface,Cocoa,Applescript,我正在尝试自动化一些任务,在这些任务中,我需要在对话框上显示文本(6位代码) 可访问性检查器显示了以下层次结构: 我是AppleScript领域的初学者,读过一些类似的例子: set myText to textField's stringValue() as text 但我不确定这是否适用于我的情况,因为可访问性检查器没有显示包含6位代码的NSTextFieldCell的任何变量名 如何提取NSTextFieldCell中的6位代码并可能返回此值,以便shell脚本可以使用此代码 我现在

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

可访问性检查器显示了以下层次结构:

我是AppleScript领域的初学者,读过一些类似的例子:

set myText to textField's stringValue() as text
但我不确定这是否适用于我的情况,因为可访问性检查器没有显示包含6位代码的
NSTextFieldCell
的任何变量名

如何提取
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.

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

出现此错误是因为您必须参考流程“FollowUI”的
窗口1

你的代码太复杂了,你只需要检查这个过程是否存在

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
,以确保它引用了当前引用(文本字段)


由于您不向窗口发送按键或鼠标事件,因此无需激活任何内容。

不是答案,但我无法将代码粘贴到注释中。下面是获取UI元素的技巧。点击Command-Shift-4以获取带有坐标的光标。瞄准UI元素并记住坐标。单击以返回箭头光标。使用此脚本中的坐标

activate application "FollowUpUI"
tell application "System Events"
    tell application process "FollowUpUI"
        click at {290, 150}
    end tell
end tell

必须允许脚本编辑器控制计算机。您可以在System prefs、Security&Privacy、Privacy中进行设置。

您必须在AppleScript中使用(丑陋的)GUI脚本和
系统事件。您无法使用Cocoa访问其他应用程序/流程的UI元素。请您为我指出正确的方向,或者举个例子?我不介意一个丑陋的解决方案。你必须
告诉应用程序“系统事件”告诉进程“[进程名称]”告诉窗口[1]告诉组1告诉文本字段1将值设置为其值
[]
中的所有值都是任意的,并且是没有括号的真实代码。如果我理解正确,这可能需要一些“点击并试用”。如何在
[]
中找到正确的值。我是否可以打印出
窗口
,以找到正确的值?抱歉,我对这个很陌生。这比打电话试听要少一点烦人。首先,您需要获取进程的名称。应用程序的名称似乎是
FollowUpUI
,因此将该名称与
告诉应用程序“系统事件”的结果进行比较,以获得进程的名称。它很可能是窗口1(除非有另一个不可见的窗口)。你必须使用
系统事件
,你不能直接访问应用程序,它当然不能编写脚本。谢谢@vadian,我正在打开对话框进行测试。这两个代码段仍然抛出相同的错误-
System Events发生错误:无法获取进程“FollowUpUI”窗口1的组1的文本字段1。无效索引
。在tell process语句之后,我放置了一个
say“found”
语句来检查该进程是否存在。再次感谢您的帮助。那么参考资料是错误的。您可以使用像
UI浏览器
(不是免费的,但可能有试用期)这样的工具,或者像
脚本调试器
(也不是免费的)这样的编辑器,它有一个属性检查器。或者,当受影响的窗口打开时,您必须
记录
从根(进程)到目标(文本字段)的
UI元素
,以找出引用链。PS:我怀疑它不是文本字段,而是其他内容–如
…单元格
显示是的,它不是文本字段。可访问性检查器将其称为
NSTextFieldCell
applescript
是否支持
NSTextField
?此外,如果我使用
脚本调试器
或类似工具,它们会显示与辅助功能检查器不同的层次结构吗?例如
UI浏览器
可以为所选引用提供实际的AppleScript代码。上面提到的两个工具都可以提供更多关于UI元素的信息,比如类和属性。我需要在按下Done键之前提取6位代码。