Swift   发布时间:2022-04-29  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了swift – 我怎么能尽可能地从OSX上最前面的窗口/文档中获取所有文本?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我希望能够从屏幕最前面的窗口中获取所有文本,将其传送到URL解析器并从解析的文本中选择要打开的URl.

为此,我需要一种方法来访问最前面窗口的所有文本内容.我已经接近使用applescript但我无法找到获取实际文本的方法.我怀疑swift可能能够提供帮助,但我很遗憾甚至谷歌这个,因为我的大多数搜索最终只能找到一些简单的方法,比如从Chrome中的标签获取网址等.

这是我想要的要点:

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上最前面的窗口/文档中获取所有文本?全部内容,希望文章能够帮你解决swift – 我怎么能尽可能地从OSX上最前面的窗口/文档中获取所有文本?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。