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

[MacPerl] droplet2txt



I've found the below script most useful when I've wanted to make
plaintext copies of directories full of droplets/CGIs/runtimes.
Modify and distribute as you like.

#!Perl
# Droplet2TXT
# For each MacPerl droplet, Perl CGI, or Runtime dropped on me
#  (or any such files in any directories dropped on me), make
#  a similarly-named file (by appending a ~) that is a text
#  copy of that file -- i.e., the Perl source is copied from the
#  resource fork of the source file (e.g., Sean:poyl:oy) into
#  the data fork of the destination file (Sean:poyl:oy~).
#  (No other resources are read from the source file; so window
#  position et al. are lost in the destination.)
#
# sburke@netadventure.net 1998-03-16
use Mac::Memory;
use Mac::Resources;
use File::Find;

exit unless @ARGV;
find(\&droplet2text, @ARGV);
print "Done\n";
exit;

sub droplet2text {
  my $SPEC = $File::Find::name;

  return unless -f $SPEC;

  my($creator, $type) = MacPerl::GetFileInfo($SPEC);
  return unless $creator eq 'MrPL' and $type eq 'APPL';
  # Otherwise it can't be a droplet, Perl CGI, or Runtime

  my $refnum = FSpOpenResFile($SPEC, 1);
  unless(defined($refnum)) {
    print "$SPEC looks like a droplet but has no resource fork!\n";
    return;
  }

  my $handle_128 = Get1Resource('TEXT', 128);

  if( $handle_128 ) {
    $out = $SPEC . '~'; # the magic filename transform

    print "$SPEC => $out\n";
    if (open(OUT, ">$out")) {
      print OUT $handle_128->get; # slurp and dump
      close(OUT);
      MacPerl::SetFileInfo('R*ch', 'TEXT', $out);
      # Make BBEdit own it
      utime( (stat($SPEC))[8,9] , $out); # just cuz
    } else {
      print "Couldn't open $out\: $!\n";
      #Filename too long, maybe?
    }
  } else {
    print "No TEXT resource #128 in $SPEC\n";
  }

  CloseResFile $refnum;
}
__END__

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