Re: Event to trigger writeSelectionToPasteboard
Re: Event to trigger writeSelectionToPasteboard
- Subject: Re: Event to trigger writeSelectionToPasteboard
- From: Peter Lübke <email@hidden>
- Date: Sat, 1 Jan 2011 15:39:38 +0100
You can copy a selection using the Accessibility API:
First get the UIElement for the application's "Copy" menu item.
Then invoke "AXPress" on it.
Drawback is that you will have to ask the user to enable
Accessibility if it is not enabled.
To get an idea about Accessibility, look at Apple's "Accessibility
Inspector" app, which also contains a bunch of interesting code samples.
Peter
Am 01.01.2011 um 10:32 schrieb Graham Cox:
On 01/01/2011, at 6:43 AM, Peter Watkins wrote:
I know that each Cocoa app implements writeSelectionToPasteboard
(), and I'm
guessing this is how services interact with running apps. Each
service is a
separate short-running process. Sothere must be some sort of IPC
to get the
selection from the running app into the service's pasteboard. If I
can
figure out what that IPC is, I can send a message to a running
application,
and this would avoid flashing the menu bar.
Any ideas on getting another app to run its
writeSelectionToPasteboard()
method?
Read the Services Implementation Guide:
http://developer.apple.com/library/mac/#documentation/Cocoa/
Conceptual/SysServices/introduction.html
The app needs to be written to be services aware, and implement the
protocols specified in the guide. If not, you can't do what you're
doing for any arbitrary app. Between the Cut or Copy menu command
and data being put on the pasteboard, the app can do whatever it
wants, there is no 'standard' method that gets called and the
method names are arbitrary (even the action method that responds to
the Copy command might not be called -copy:)
There's no 'Copy' or 'Paste' event. Some apps might expose these
through applescript - again, there's no guarantee.
What are you really trying to achieve? If you implement your
service in a standard way, apps that are services aware will be
able to use it. If not, they won't, and you have to live with it.
You can't force an app to become services aware if it wasn't
written to be.
--Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden