[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Drag & Drop Text Selection to Droplet Question



Chip asks:

> How does MacPerl process a text selection that has be dropped
> on a droplet?
> 
> Can this be done?  Does the Mac handle the selection as a file
> (type/creator) or some chunk of memory?

Well, this depends on what you mean. If you mean, can you drag
and drop selected text from an application such as MS-Word onto
a droplet, the answer is NO (at least not under MacOS7). If you
mean can you drag and drop a text clipping file from the desktop
onto a droplet, the answer is absolutely. It's just a file like
any other file... well... not **JUST** like any other file. The
text is actually stored in the resource fork in a resource type
"TEXT" and ID=256... which means you'll have to use resource
manipulation commands to get at the data you care about...

I wonder why Apple doesn't store this as text in the data fork?
I have a theory - Apple thought it was such a swell concept,
they wanted to insure users used it as much as possible... after
all, once you create a text clipping file, the only way to use
it was to drop it back onto the content of an application
document... you can't drop it onto your favorite text or word
processor like an ordinary text document...

> Help with snipits please!

Here's a quick and dirty snippet that will let you drop a text
clipping file on a droplet and it prints the embedded text to
your standard output (just save it as a droplet). It ignores
files that are not text clippings and only does one file at a
time. I've not done extensive error checking or robustified it...
Hey, it's just a snippet!


#! perl -w

use Mac::Resources;
use Mac::Memory;

my($creator, $type) = MacPerl::GetFileInfo(@ARGV);

if (defined($type)) {
  if ($creator eq 'drag' and $type eq 'clpt') {
    $fileref = FSpOpenResFile(@ARGV, 1);
    if (defined($fileref)) {
      $reshand = Get1Resource('TEXT', 256);
      if ($reshand) { print $reshand->get() };
    }
    CloseResFile $fileref;
  }
}


***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch