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

[MacPerl] two things



First, a code snippet.  You select a file and type in arguments, and it
runs the script under MPW and returns the results.  Basically. a quick way
to run a command line program, but it won't work with interactive programs,
of course.

  #!perl -wl
  use Mac::GetFile;
  my $file = $ARGV[0] ||
    get_file('Select a MacPerl script to run', '', ['TEXT']);
  $file =~ s/(["{}`¶])/¶$1/g;
  my $args = MacPerl::Ask('Script arguments?');
  print `perl "$file" $args`;

Second, a package I wrote that gets a file easily.  It uses Nav Services if
you have it, and StandardFile if you do not.  As Navigation Services
becomes more popular, and when Mac::Navigation is standard equipment,
something like this will likely be needed.  Maybe people can shout out some
thoughts and we can put something together, and maybe lobby Matthias to
include it in MacPerl if it works well.  Maybe have a corresponding
put_file(), choose(), etc.

package Mac::GetFile;
use Mac::Files;
use Exporter;
use vars qw(@EXPORT @ISA $VERSION);
@ISA = qw(Exporter);
$VERSION = 1.00;
@EXPORT = qw(get_file);
#-----------------------------------------------------------------#
=pod

=item get_file(PROMPT, DEFAULT, TYPES);

=cut

sub get_file {
    my($text, $default, $types, $file) = @_;
    if (eval {require Mac::Navigation}) {
        my($options, $nav);
        Mac::Navigation->import();
        $options = NavGetDefaultDialogOptions();
        $options->message($text);
        $options->windowTitle($text);
        local($^W) = undef;
        $nav = NavChooseFile($default, $options,
            bless({}, 'NavTypeListHandle'), 0, 0, sub{
                return unless (my $ft = $_[1]->fileInfo->finderInfo->fdType);
                return 1 if   ($_[1]->isFolder());
                foreach my $type (@$types) {return 1 if $ft eq $type}
                return;
            }
        );
        return if (!$nav || !$nav->file(1));
        $file = $nav->file(1);
    } else {
        require Mac::StandardFile;
        my($get);
        Mac::StandardFile->import();
        $get = StandardGetFile(undef, 0);
        return if (!$get->sfGood());
        $file = $get->sfFile();
    }
    return $file;
}
#-----------------------------------------------------------------#
__END__


--
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])

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