gpt4 book ai didi

swift - 我怎样才能尽可能一般地从 OSX 上最前面的窗口/文档中获取所有文本?

转载 作者:搜寻专家 更新时间:2023-10-31 19:37:47 25 4
gpt4 key购买 nike

我希望能够从屏幕最前面的窗口中抓取所有文本,将其通过管道传输到 url 解析器,然后从解析的文本中选择要打开的 url。

为此,我需要一种方法来访问最前面窗口的所有文本内容。 我已经接近使用 applescript,但我找不到获取实际文本的方法。我怀疑 swift 可能会有所帮助,但我什至不知道如何用谷歌搜索这个,因为我的大部分搜索最终只找到了一些微不足道的方法,比如从 chrome 中的标签获取 url 等。

这是我想要的要点:

tell the frontmost application
get contents of frontmost window as text
end tell

最佳答案

您是否尝试过获取特定应用程序的所有 UI 元素?

set appname to "System Preferences" -------------------------- Set this to the App you want to look at

display dialog "Set the app you want to look at" default answer "System Preferences" buttons {"OK"} default button 1
set appname to text returned of result

set winstuff to "defaultval"
set menustuff to "defaultval"

tell application appname
activate
end tell

delay 0.5

tell application "System Events"
tell process appname
set winstuff to entire contents of front window
set menustuff to entire contents of menu bar 1
end tell
end tell
--return winstuff & "\r\r\r\r" & menustuff -- comment this out to get just winstuff
return winstuff -- comment this out too to get just menustuff
--return menustuff

关于swift - 我怎样才能尽可能一般地从 OSX 上最前面的窗口/文档中获取所有文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38672264/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com