Search code examples
objective-ccocoaosx-elcapitan

Mac get selected text from foremost window


I am building a menu app that needs to be able to capture selected text and then act on it. This will of course be a sandboxed app. Is there a standard way of capturing selected text from any window in the foreground? This could be any app, a browser and so on.


Solution

  • I don't think you can do what you want to do. As far as I know, the only way to look at text in another app is by using the "assistive" APIs. But according to the 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