At 12:03 pm +0100 13/10/03, Alan Fry wrote:

What I miss most is the MacPerl droplet, on which you could drop a file, extract the path (into ARGV) and do something with the file.

You can do this with Applescript (see below, with the advantage over a MacPerl droplet that you don't have to watch the thing launch if you save it as stay-open


Is there anyway one can get back to this functionality in MacOS X? Experiments with AppleScript have not been rewarding. Sure, you can write an applet which will extract the full path name from a file dropped on it. But the path is the old Mac-style colon separated directory path. What can you do with that?

All this is taken care of. See below


Even assuming you could translate the Mac-style path to a Unix-style path (in AppleScript!), how can you pass the path to a Perl script? I have tried "telling" application "Terminal"..

B*gger the Terminal. This is not 1975 :-) though I know there are some geeks not too far away who behave as if it were.


So I am stuck -- wondering if things might perhaps be more cheerful with WinPerl?

There are some nice features and at least one excellent perl editor for Windows, but once you've crossed a few hurdles on the Mac you'll be better off than in Windows.on


This script is a demostration that you can run as a proof of concept. All it does is open a TextEdit window listing the pathnames of the files you dropped on the droplet, but from this wou will see that everything is possible. You just need to get familiar with a few basic things in AppleScript and pay special attention to the manipulation of pathnames/filespecs -- alias, file specification, POSIX file. posix path of .... etc. These have to be right. Use the event viewer in Script Editor to see where you go wrong.

There is also (Sherm Pendley's ??) Perl Droplet for MacOS X which does the same sort of thing in a perlier way.


This script has two handlers to create and write out the perl script, but these are just there for the demo.


-- save as application (stay-open if you like)
on open _filelist
 tell app "Finder" to set f to container of (path to me) as Unicode text
 set _perlfileMac to f & "test.pl" as file specification
 set _perlscriptpath to quoted form of POSIX path of _perlfileMac
 writePerlFile(_perlfileMac, scriptText()) -- if you dont have a file there
 set _args to space
 repeat with _file in _filelist
  set _path to quoted form of POSIX path of _file
  set _args to _args & space & _path
 end repeat
 do shell script "perl " & _perlscriptpath & _args
end open
on writePerlFile(f, s)
 open for access f with write permission
 set eof f to 0
 write s to f
 close access f
end writePerlFile
on scriptText()
 "$f = qq~/tmp/test.txt~;
 open F, qq~>$f~;
 for (@ARGV){
  print F qq~$_$/~;
 }
 `open -e $f;`" as string
end scriptText




Reply via email to