Crashing the OS X Pasteboard

Posted by Ben Packard on Stack Overflow See other posts from Stack Overflow or by Ben Packard
Published on 2010-05-09T07:51:43Z Indexed on 2010/05/09 7:58 UTC
Read the original article Hit count: 360

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];

© Stack Overflow or respective owner

Related posts about cocoa

Related posts about objective-c