是否可以从当前光标位置获取Pages应用程序的文本?
我的要求是,当用户在“页面”中键入某些内容时,我必须为他们键入的单词显示建议。
所以我想从“页面”应用程序中找到当前或最后一个单词,靠近当前光标位置。
使用AppleScript或Accessibility?
未选择文本。
我也不想找“服务”。
对于“页面”以外的应用程序,我使用了可访问性和appleScript。但我找不到任何方法。
我也尝试过下面的AppleScript,但是由于某些原因,它在“脚本编辑器”中工作得很好,但是当我在代码中使用它时,它会进入无限循环。
tell application "Pages"
activate
end tell
tell application "System Events"
tell application "System Events"
key code 123 using {shift down, command down} -- shift-command-left
end tell
tell process "Pages"
keystroke "c" using {command down}
delay 1
tell application "System Events"
key code 124 -- shift-command-left
end tell
set myData to (the clipboard) as text
return myData
end tell
end tell
如果我在我的应用程序中运行这个AppleScript,它只会冻结我的Mac,我必须强制退出Mac来停止它。