Search code examples
swiftmacoscocoasandboxkeyboard-events

Copy and pasting selected text from the current, from a Mac sandboxed application


I am trying, from a sandboxed menubar application, to get the selected (highlighted) text in the current application. I was using accessibility before and traversing the main menu of the application until finding the copy item but unfortunately, I need to sandbox the application and this is no more a valid approach.

I would like to simulate the ⌘ + C keyboard shortcut but so far all my attempts failed.


Solution

  • so far all my attempts failed

    There is a reason for that...

    A core purpose of the sandbox is to provide isolation between applications, to prevent one application from accessing the data of another. So what you are asking is how to break out of the sandbox...

    If you are writing accessibility software take a look at How to use Accessibility with sandboxed app? for maybe the smallest glimmer of a hope.

    Otherwise your current path is a (hopefully, its a sandbox) dead-end, security has a price, sorry.