Mac 从最前面获取选定的文本 window

Mac get selected text from foremost window

我正在构建一个菜单应用程序,它需要能够捕获选定的文本然后对其进行操作。这当然是一个沙盒应用程序。是否有一种标准方法可以从前台的任何 window 中捕获选定的文本?这可以是任何应用程序、浏览器等。

我不认为你可以做你想做的事。据我所知,在另一个应用程序中查看文本的唯一方法是使用 "assistive" API。但是根据 App Sandbox Design Guide,

you cannot sandbox an assistive app such as a screen reader, and you cannot sandbox an app that controls another app