Crashing the OS X Pasteboard
- by Ben Packard
I have an application that reads in text by emulating CMD-C copy commands and reading the pasteboard - unfortunately this the only way to achieve what I need. Occasionally, something goes wrong in execution (not sure yet if it's related to the copy command or not) and the app crashes. Once in a while, this has a knock on effect on the system-wide pasteboard - any other application that is running will crash if I attempt a copy, cut, or paste.
Is there a robust way to handle this - something I should be doing with the NSPasteboard before exiting? Any information on what might be happening is appreciated.
For completeness, here are the only snippets of code that access the pasteboard:
Reading from the pasteboard:
NSString *pBoardText = [[NSPasteboard generalPasteboard]stringForType:NSStringPboardType];
Initially clearing the pasteboard (I run this only once, at launch):
[[NSPasteboard generalPasteboard] declareTypes: [NSArray arrayWithObject:NSStringPboardType] owner: self];
[[NSPasteboard generalPasteboard] setString: @"" forType: NSStringPboardType];