Question

I'm attempting to copy an NSString to the pasteboard from within an NSBundle that is loaded inside another program as a plugin.

For some reason, [NSPasteboard generalPasteboard] is returning nil.

My code is from Apple's NSPasteboard documentation and NSPasteboard programming guide:

NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];

// Outputs: (null)
NSLog(@"%@", pasteboard);

[pasteboard clearContents];
BOOL copiedToPasteboard = [pasteboard writeObjects:@[@"The string"]];

Is there something I could have inadvertently done to cause this?

Was it helpful?

Solution 2

My problem was solved by reinstalling my OS.

I can only assume that something, somewhere, at some time became corrupted, causing this infuriating issue.

OTHER TIPS

I have built a minimal app that loads a bundle and added logging of the value returned by [NSPasteboard generalPasteboard] at each step. Unfortunately, I was not able to reproduce this issue. Here is the output that I get:

NUAppDelegate> init:<NSPasteboard: 0x100647740>
NUAppDelegate> awakeFromNib:<NSPasteboard: 0x100647740>
NUAppDelegate> applicationDidFinishLaunching::<NSPasteboard: 0x100647740>
Loading plugin
Plugin> init:<NSPasteboard: 0x100647740>
Plugin> someMethod:<NSPasteboard: 0x100647740>

Without more details I don't see how we can find an answer. Do you have some code we can download or inspect?

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