【发布时间】:2018-02-19 12:01:59
【问题描述】:
我正在尝试自动化一些需要在对话框中显示文本的任务(6 位代码)。
Accessibility Inspector 揭示了以下层次结构:
我是 AppleScript 领域的初学者,并且已经阅读了一些可以像这样完成类似操作的示例:
set myText to textField's stringValue() as text
但我不确定这是否适用于我的情况,因为 Accessibility Inspector 没有显示包含 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.
我不确定这是否是语法错误。任何指针都会有所帮助。谢谢
【问题讨论】:
-
您必须在 AppleScript 中使用带有
System Events的(丑陋的)GUI 脚本。您无法使用 Cocoa 访问其他应用程序/进程的 UI 元素。 -
您能否指出正确的方向,也许是一个例子?我不会介意丑陋的解决方案。
-
你必须
tell application "System Events" to tell process "[name of process]" to tell window [1] to tell group 1 to tell text field 1 to set theValue to its value。[]中的所有值都是任意的,并且是没有括号的真实代码。 -
如果我正确理解了这一点,这可能涉及到一些“命中和试验”。我如何找到正确的值放入
[]。我可以打印出windows或groups以找到正确的值吗?抱歉,我对此很陌生。 -
它比 hit and trial 少一点烦人。首先,您需要获取进程的名称。应用程序的名称似乎是
FollowUpUI,因此将名称与tell application "System Events" to get name of processes的结果进行比较。它很可能是窗口 1(除非有另一个不可见的窗口)。 你必须使用System Events,你不能直接访问应用程序,它肯定是不可编写脚本的。
标签: objective-c macos user-interface cocoa applescript