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

Re: [MacPerl] Selecting files from MacPerl



Title: Re: [MacPerl] Selecting files from MacPerl
I've been lurking for a longtime, keeping my eye on the list but not having many questions since I'd generally been programming for a Unix box. Anyways, I finally had a project that specifically required a Perl program on the Mac and while I got most of it working, I ran into a snag. The help files were very vague on how to select files to open or save using the standard Mac dialog boxes. I hacked a workaround by running an AppleScript from the script to choose the file the user wants to manipulate and passing the result to the the script:

$import_sourcefile = MacPerl::DoAppleScript(<<END_SCRIPT);
      tell application "Finder"
               return choose file of type "TEXT"
       end tell
END_SCRIPT
A rather inelegant solution I thought. For saving the file, I had the script set the name and destination for the file rather than letting the user input their own name and save location. Even more inelegant.

Well, I'd really like to cleanup the script and use MacPerl to let the user pick the input file and save the output file in the location of their choice. But I can't seem to find any decent help or examples only "Access to Inside Macintosh is essential for proper use of these functions. Explanations of terms, processes and procedures are provided there." in the help file. Does anyone know where I can find a tutorial or have the proper usage of open and save dialogs?

Thanks for all the assistance,

David Wadson - wadsond@air.on.ca
Composing Foreman

The Chronicle-Journal
Thunder Bay, Ontario, Canada
www.chroniclejournal.com

Dear David,

examples on how to use the StandardFile dialogs are provided in the :ext:Mac:StandardFile:t folder inside your MacPerl folder. Here is also a little example, just in case the t-files are missing:

__________
#! perl -w

use Mac::StandardFile;
use strict;

# display all files of type 'TEXT', but no file filter function
my $sf_result = StandardGetFile(undef, 'TEXT');

if ($sf_result->sfGood) { # user hasn't cancelled
   print "You've selected ", $sf_result->sfFile, " \n"; # filename
   #
   # do your file opening stuff here
   #
}#if

$sf_result = StandardPutFile("User Prompt", "filename.default");

if ($sf_result->sfGood) { # user hasn't cancelled
   print "You'll save the file as ", $sf_result->sfFile, " \n"; # filename
   #
   # do your file saving stuff here
   #
}#if

__END__

HTH.

Best regards

-- Thomas