Skip to content

Instantly share code, notes, and snippets.

@Wevah
Created April 8, 2014 15:44
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Wevah/10145527 to your computer and use it in GitHub Desktop.
Save Wevah/10145527 to your computer and use it in GitHub Desktop.
Using kPasteboardTypeFileURLPromise/kPasteboardTypeFilePromiseContent
- (NSArray *)writableTypesForPasteboard:(NSPasteboard *)pasteboard {
// pasteboard must be stored away because there's no way to get it in -pasteboardPropertyListForType: :(
_currentPasteboard = pasteboard;
NSArray *types = @[(id)kPasteboardTypeFileURLPromise, (id)kPasteboardTypeFilePromiseContent];
return types;
}
// ...
- (id)pasteboardPropertyListForType:(NSString *)type {
if ([type isEqualToString:(NSString *)kPasteboardTypeFilePromiseContent])
return someUTI;
else if ([type isEqualToString:(NSString *)kPasteboardTypeFileURLPromise]) {
NSURL *directoryURL = [NSURL URLWithString:[_currentPasteboard stringForType:@"com.apple.pastelocation"]];
NSURL *finalURL = [NSURL URLWithString:[_filename stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] relativeToURL:directoryURL];
// Write your file to finalURL here
return [finalURL absoluteString];
}
}
@OscarSwanros
Copy link

OscarSwanros commented Mar 28, 2017

I can't get a hold of com.apple.pastelocation — anything I could be doing wrong?

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