<p>Is there a way to unfilter an NSPasteboard for what the source application specifically declared it would provide?</p>

<p>I'm attempting to serialize pasteboard data in my application.  When another application places an RTF file on a pasteboard and then I ask for the available types, I get eleven different flavors of said RTF, everything from the original RTF to plain strings to dyn.* values.  </p>

<p>Saving off all that data into a plist or raw data on disk isn't usually a problem as it's  pretty small, but when an image of any considerable size is placed on the pasteboard, the resulting output can be tens of times larger than the source data (with multiple flavors of TIFF and PICT data being made available via filtering).</p>

<p>I'd like to just be able to save off what the original app made available if possible.</p>

<hr>

<p>John, you are far more observant than myself or the gentleman I work with who's been doing Mac programming since dinosaurs roamed the earth.  Neither of us ever noticed the text you highlighted... and I've not a clue why.  Starting too long at the problem, apparently.</p>

<p>And while I accepted your answer as the correct answer, it doesn't exactly answer my original question.  What I was looking for was a way to identify flavors that can become  other flavors simply by placing them on the pasteboard <strong>AND</strong> to know which of these types were originally offered by the provider.  While walking the types list will get me the preferred order for the application that provided them, it won't tell me which ones I can safely ignore as they'll be recreated when I refill the pasteboard later.</p>

<p>I've come to the conclusion that there isn't a "good" way to do this.  <code>[NSPasteboard declaredTypesFromOwner]</code> would be fabulous, but it doesn't exist.</p>

[{'answer_id': 57771, 'author': 'John Calsbeek', 'author_id': 5696, 'author_profile': 'https://Stackoverflow.com/users/5696', 'pm_score': 3, 'selected': True, 'text': '<p><code>-[NSPasteboard types]</code> will return all the available types for the data on the clipboard, but it should return them <a href="http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSPasteboard_Class/Reference/Reference.html#//apple_ref/occ/instm/NSPasteboard/types" rel="nofollow noreferrer">"in the order they were declared."</a></p>\n\n<p>The documentation for <code>-[NSPasteboard declareTypes:owner:]</code> says that <a href="http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSPasteboard_Class/Reference/Reference.html#//apple_ref/occ/instm/NSPasteboard/declareTypes:owner:" rel="nofollow noreferrer">"the types should be ordered according to the preference of the source application."</a></p>\n\n<p>A properly implemented pasteboard owner should, therefore, declare the richest representation of the content (probably the original content) as the first type; so a reasonable single representation should be:</p>\n\n<pre><code>[pb dataForType:[[pb types] objectAtIndex:0]]\n</code></pre>\n'}, {'answer_id': 59715, 'author': 'John Calsbeek', 'author_id': 5696, 'author_profile': 'https://Stackoverflow.com/users/5696', 'pm_score': 0, 'selected': False, 'text': '<p>You may be able to get some use out of <a href="http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSPasteboard_Class/Reference/Reference.html#//apple_ref/occ/clm/NSPasteboard/typesFilterableTo:" rel="nofollow noreferrer"><code>+[NSPasteboard typesFilterableTo:]</code></a>. I\'m picturing a snippet like this:</p>\n\n<pre><code>NSArray *allTypes = [pb types];\nNSAssert([allTypes count] &gt; 0, @"expected at least one type");\n\n// We always require the first declared type, as a starting point.\nNSMutableSet *requiredTypes = [NSMutableSet setWithObject:[allTypes objectAtIndex:0]];\n\nfor (NSUInteger index = 1; index &lt; [allTypes count]; index++) {\n    NSString *aType = [allTypes objectAtIndex:index];\n    NSSet *filtersFrom = [NSSet setWithArray:[NSPasteboard typesFilterableTo:aType]];\n\n    // If this type can\'t be re-created with a filter we already use, add it to the\n    // set of required types.\n    if (![requiredTypes intersectsSet:filtersFrom])\n        [requiredTypes addObject:aType];\n}\n</code></pre>\n\n<p>I\'m not sure how effective this would be at picking good types, however.</p>\n'}]
['https://Stackoverflow.com/questions/54760', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4233/']