Event to trigger writeSelectionToPasteboard
Event to trigger writeSelectionToPasteboard
- Subject: Event to trigger writeSelectionToPasteboard
- From: Peter Watkins <email@hidden>
- Date: Fri, 31 Dec 2010 11:43:40 -0800
I'm writing an app that lets the user select text in one program and paste
it into another by middle-clicking the mouse button. This roughly emulates
the X11 selection buffer.
The first version I wrote used event taps to detect when the user dragged a
selection (doesn't work for a double-click select or shift-arrow select). It
then compiled and ran an apple script to "get the contents of the selection"
in the frontmost app. When the user middle-clicked, the app would retype
(using CGEvents) everything it got from the apple script.
This worked OK except:
1) Only a few apps support "get the contents of the selection"
2) It's slow to send events for every keystroke (and undo-buffers get
confused)
The next version called two services I made, "Copy Selection" and "Paste
Selection". This works with all Cocoa apps (fixes #1), is fast (fixes #2),
but I haven't found a way to programmatically invoke a service (in another
app). The best I could come up with was setting command-key equivalents for
the services and sending those command-keys through UI scripting. The nasty
side effect of this is that every time you drag a selection, the app's app
menu gets selected. This is unacceptable-I don't want my menu bar flashing
each time I drag the mouse.
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?
Thanks,
Peter
_______________________________________________
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