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

Re: [MacPerl] Basic Question



Chip,

I would not call this a basic question.  (I also don't think you 
supplied enough information.)

>I downloaded a script from a web site which processes a data file to 
>make a Palm file.

 From your message, I infer this was written to run under Windows.  Is 
that correct?  (The rest of my message assumes so.)

>I need to be able to pass two arguments (file names) to the script. 
>If I run the script from the menu it produces an error because it 
>did not have those arguments). How do I pass those arguments?

This problem occurs because MacOS lacks a command line.

Two commonly used solutions are:

1)

>I tried modifying the original script to work around the problem. I 
>found an example script which opened a choose file dialog. I tried 
>using that, and it appeared to work.

...you already found; it looks like you have already solved this problem.

2) You save the file as a droplet.  (From the File menu.)  Then, the 
names (paths) of whatever files you drop onto the droplet are 
provided to MacPerl as if they had been given on the command line 
(e.g. they are in @ARGV).  However, if you are specifying an input 
filename and an output filename, and the output file does not 
pre-exist, that doesn't work.  What I do in such cases is to modify 
the script so that the name of the output file is automatically 
generated (e.g. by appending '.out' to the input file name).

>The Palm file, however, appeared to be incorrectly formatted. That 
>brings up another question. Can the difference in file systems make 
>it mandatory to change the original script to be compatible with the 
>Mac for making a Palm file?

This is why I think this is not a basic question.  This is not so 
much a Windows Perl/MacPerl issue, but Windows/MacOS and Palm issues.

1) It may be that the particular file has utterly different formats 
under Windows and under MacOS, in which case the script would need a 
major rewrite (since it really is doing an entirely different job) 
and you would need to get documentation for the Mac file format to 
accomplish that.

2) It may even be that the particular file represents a functionality 
that Palms don't have on a Mac, in which case there is nothing you 
can do.

3) However, it may only be that the filetype is wrong.  Under 
windows, filetype and the name of the program that should be used to 
open that file are always linked and are specified by a filename 
extension; a Microsoft Excel file has the extension .xls, for 
example.  On the Mac, filetype and creator are independent (so that 
two different text files can be opened by two different programs) and 
is specified independently of the name.  A Microsoft Excel file on a 
Mac has a filetype of XLS8 and a creator of XCEL, for example.

One way to accomplish the setting of filetype and creator which would 
involve minimal changes to your script is to use the function:

MacPerl::SetFileInfo

If the path to your output file is contained in $f
...and you want to change the creator and file type to:
R*ch and TEXT (a text file created by BBEdit)
...just add the following line at the end of your script:

MacPerl::SetFileInfo('R*ch', 'TEXT', $f);

If you have a file of the type you are trying to create, you can find 
out its type and creator by saving the following script:

foreach $f (@ARGV) {
     @tmp = MacPerl::GetFileInfo($f);
     $t = join(" - ", @tmp);
     print "$t - $f\n";
}

...as a droplet and dropping that file on it.

It will display the creator, the filetype, and the filename, e.g.

MSIE - TEXT - Leucine:Desktop Folder:tmp3.html

... a text file created by Internet Explorer on my desktop with the 
name of tmp3.html

Hope this helps.

-David Steffen-
David Steffen, Ph.D.
President, Biomedical Computing, Inc. <http://www.biomedcomp.com/>
Phone: (713) 610-9770 FAX: (713) 610-9769 E-mail: steffen@biomedcomp.com

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org