The solution I went with, which seems to work for initial testing, is roughly as follows:
use File::Basename; use Cwd qw[realpath]; my $opts_tool = get_optstool(); system("/usr/bin/open '$opts_tool'") and die "Couldn't execute $opts_tool: $!"; sub get_optstool { my $optstool = "Optimize Mac.app"; my $cur_path = dirname(realpath $0); my $rel_path = "../Resources"; my $opts_loc = "$cur_path/$rel_path/$optstool"; return $opts_loc; } Written that way so that If I later want to call out to a different tool, it's clearer to me what will need to be tweaked to do so. Keep in mind that, by being wrapped in a Pashua GUI on the Mac, the GUI user will be invoking this from wherever it happens to be on their filesystem, which in turn means that the Finder or Launch Services or what have you ends up being responsible for handing off the runtime environment to the script. This approach seems to work so far for the use cases I'm picturing -- the /Applications folder, a random folder with a space character in the path, a USB drive, and a network drive. (Part of me wonders if this whole thing would have worked better in Camelbones as one app instead of two, but one of the constraints is that some of the things it will do won't require admin access, but other things will, so I have to be able to prompt for a password if certain options are selected, then hand that off to the helper app[s] accordingly. I didn't really see how to get a single app to force that prompt if it's needed.) -- Chris Devers On 3/10/09, Doug McNutt <dougl...@macnauchtan.com> wrote: > At 20:25 +0000 3/10/09, John Delacour wrote: >>At 21:10 -0600 9/3/09, Doug McNutt wrote: >> >>>At 22:24 -0400 3/9/09, Chris Devers wrote: >>>>How can a Perl script reliably, portably resolve the path inside which >>>>it is running?... >>> >>>$0 That's a zero. Has always worked for me to produce a full path >>>to a running perl script. >>> >>>...There is a module "cwd"... >> >>or rather Cwd. $0 will give the name but not the full path, so I'd suggest >>the following: >> >>#usr/bin/perl >>use Cwd; >>my $currentdir = cwd(); >>print "$currentdir/$0\n"; > > Interesting. It turns out that I rarely call a stored perl script > without specifying a full path in the call. I'm getting a full path > in $0 when I do that. There may be more to think about. The stuff I > just checked calls the script itself which has been made executable > rather than making a call to perl with the argument being the path to > the script. I also don't know about a stored script placed in a > directory that's included in $PATH but is not in $PWD. > > "portable" seems to be the key here. Modules good for that. > > -- > -> Stocks are getting pilloreid <- > -- -- Chris Devers