• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Help with pasteboard
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help with pasteboard


  • Subject: Re: Help with pasteboard
  • From: Rainer Brockerhoff <email@hidden>
  • Date: Thu, 18 Oct 2001 11:11:58 -0200

Date: Wed, 17 Oct 2001 16:52:38 -0500
From: Brian Webster <email@hidden>
The way to create a file in the Finder is to write data of type
NSFileContentsPboardType to the pasteboard.
...
Anyway, the code to write a string to the pasteboard in such a
manner would be something like this:

NSString *stringToWrite;
NSPasteboard *pboard;
NSFileWrapper *stringFile;
NSData *stringData;

[pboard declareTypes:[NSArray
arrayWithObjects:NSStringPboardType, NSFileContentsPboardType,
nil]];
[pboard setString:stringToWrite forType:NSStringPboardType];
stringData = [stringToWrite
dataUsingEncoding:NSMacOSRomanStringEncoding];
stringFile = [[NSFileWrapper alloc]
initRegularFileWithContents:stringData];
[stringFile setPreferredFilename:@"String file"];
[pboard writeFileWrapper:stringFile];
[stringFile release];

That's nice. Thanks for the snippet. I hadn't really looked at NSFileWrapper before.

From what I've seen in the docs this works OK for the new-style data files, but I'd been hoping for a way to include resource forks (or rather, custom icons, which use the resource fork) in a dragged-to-the-Finder item. Apparently there's no way to do so, right?

An alternative would be for my app to get some feedback about the location where the file ended up, so I'd go after it and insert the custom icon afterwards... is there such a thing? (If there's a TFM to R, just tell me which)


--
Rainer Brockerhoff <email@hidden>
Belo Horizonte, Brazil
"Originality is the art of concealing your sources."
http://www.brockerhoff.net/ (updated Oct. 2001)


  • Follow-Ups:
    • Re: Help with pasteboard
      • From: Charles Srstka <email@hidden>
  • Prev by Date: AppKit without user (Re: What happens to the AppKit Framework when an user logout ?)
  • Next by Date: Re: Ownership of nib instances
  • Previous by thread: Re: Help with pasteboard
  • Next by thread: Re: Help with pasteboard
  • Index(es):
    • Date
    • Thread