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

Re: [MacPerl] drag and drop with a droplet



> Maybe I am lazy can't find the answer by myself
> have created a script which search and replace character.
> Now I want to let my script work like stuffit expander
> drag and dropp of several files will get  a sevearl new files
> how I do?

Have the first line of the script be "#!perl -i" and then read
the Perl docs section on "-i" (in perlrun.pod).
Save the script as a droplet.
Drop things on it.

However, note that (at least last I checked) the new files
created by -i ([re|dis]placing old ones with the same name) will
not inherit the owner and creator types of their source files --
nor (I assume) other things like resource fork contents, etc.
If that's important to you, don't use -i; manually deal with
the filenames in ARGV (here, probably using some OS-level
copy method to preserve the cruft in the destination file before
you go overwriting its data fork's contents).
But for just plain text files, -i has done me fine.


And consider this middling kludge:

#!perl -i
#I can only cope with one file dropped on me

sub BEGIN {
  exit unless @ARGV == 1 and -f $ARGV[0];
  $file = $ARGV[0];
}

while(<>) {
  whatever;
  last if bad_things;
  print;
}

sub END {
  &MacPerl::SetFileInfo('MOSS', 'TEXT', $file);
}

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