Hi, guys! Does anybody know what’s the ObjC equivalent for
set the clipboard to ("/path/to/a/file" as POSIX file)
in order to paste that file in the Finder?
Thank you
Hi, guys! Does anybody know what’s the ObjC equivalent for
set the clipboard to ("/path/to/a/file" as POSIX file)
in order to paste that file in the Finder?
Thank you
Hi,
this is the equivalent
NSString *posixPath = @"/path/to/a/file";
CFStringRef hfsPath = CFURLCopyFileSystemPath((CFURLRef)[NSURL fileURLWithPath:posixPath], kCFURLHFSPathStyle);
NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
[pasteboard declareTypes:[NSArray arrayWithObject:NSPasteboardTypeString] owner:nil];
[pasteboard setString:[NSMakeCollectable(hfsPath) autorelease] forType:NSPasteboardTypeString];
…well, the AS code allows me to paste the file in the Finder, while the ObjC code doesn’t…
After HOURS AND HOURS AND HOURS of searching around, I finally got the answer…
NSArray *fileList = [NSArray arrayWithObjects:filePath1, filePath2, nil];
NSPasteboard *pboard = [NSPasteboard generalPasteboard];
[pboard declareTypes:[NSArray arrayWithObject:NSFilenamesPboardType]
owner:nil];
[pboard setPropertyList:fileList forType:NSFilenamesPboardType];
Just curious where you ended up finding it. FWIW, I had to add copying into my app, and I went into the XCode docs, looked up NSPasteboard… then read the Pasteboard programming guide. There was thankfully a decent amount of sample code and then I was able to easily adapt it to my exact needs. So my point is the XCode docs are a good starting point, sometimes the web doesn’t give you what you want very easily.
I don’t remember…