Skip to content

Instantly share code, notes, and snippets.

@JohnCoates
Created February 2, 2016 19:11
Show Gist options
  • Save JohnCoates/47218d0f82f97219685c to your computer and use it in GitHub Desktop.
Save JohnCoates/47218d0f82f97219685c to your computer and use it in GitHub Desktop.
Mac OS X Pasteboard Viewer : NSPasteboard extract
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
int main(int argc, char *argv[]) {
@autoreleasepool {
NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
NSLog(@"items: %@", pasteboard.pasteboardItems);
for (NSPasteboardItem *item in pasteboard.pasteboardItems) {
NSLog(@"types: %@", item.types);
for (NSString *type in item.types) {
NSData *data = [item dataForType:type];
NSString *string = [item stringForType:type];
NSLog(@"%@: %@", type, string);
NSLog(@"%@: %@", type, data);
NSString *writeOutPath = [NSString stringWithFormat:@"~/Temp/%@", type];
writeOutPath = [writeOutPath stringByExpandingTildeInPath];
[data writeToFile:writeOutPath atomically:YES];
}
}
}
}
@JohnCoates
Copy link
Author

I recommend running this with CodeRunner 😃 https://coderunnerapp.com/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment