swift – 我怎么能尽可能地从OSX上最前面的窗口/文档中获取所有
发布时间:2020-12-14 04:31:18 所属栏目:百科 来源:网络整理
导读:我希望能够从屏幕最前面的窗口中获取所有文本,将其传送到URL解析器并从解析的文本中选择要打开的URL. 为此,我需要一种方法来访问最前面窗口的所有文本内容.我已经接近使用applescript但我无法找到获取实际文本的方法.我怀疑swift可能能够提供帮助,但我很遗憾
我希望能够从屏幕最前面的窗口中获取所有文本,将其传送到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 & "rrrr" & menustuff -- comment this out to get just winstuff return winstuff -- comment this out too to get just menustuff --return menustuff (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |