Question

"NSPasteboard objects transfer data to and from the pasteboard server. The server is shared by all running applications. It contains data that the user has cut or copied, as well as other data that one application wants to transfer to another. NSPasteboard objects are an application’s sole interface to the server and to all pasteboard operations.

An NSPasteboard object is also used to transfer data between applications and service providers listed in each application’s Services menu. The drag pasteboard (NSDragPboard) is used to transfer data that is being dragged by the user."

I found this in apple's NSPasteboard documentation. So far I only know how to use the pasteboard for simple copy-paste purposes. What I'm interested in knowing is how data for non-copy-paste purposes can be transferred through the pasteboard server between applications using contextual menus instead of drag-and-drop. For instance, if a user right-clicks a word and clicks "Look up in Dictionary" in the contextual menu, the word is then (presumably) sent to the Dictionary app through the pasteboard.

Can someone demonstrate a proof-of-concept app showing how to access data in the pasteboard server that stores words that a user has used "Look up in Dictionary" on?

Was it helpful?

Solution

It is not necessary for us to find the "Look up in Dictionary" pasteboard. (if there is one). But there is an NSPasteboard class method that sticks out to me for this use if you wanted to transfer data via pasteboard across your applications.

+ (NSPasteboard *)pasteboardWithName:(NSString *)name

Just use the same name for both apps and you can transfer data between them. Just make sure to call - releaseGlobally on this pasteboard when you are done with it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top