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

[MacPerl] Mounting Volumes (again...)




I searched the archives (thank you sandra for the web pages!) and found two
references to the same question, but no real answer.  Sorry if this is a
repeat.

The user level task is to write a (MacPerl) script that will mount a volume
across the network (a passwd has to be given - it can be hardcoded into the
MacPerl script...), log some stuff (user info and the like), then run a
CodeWarrior installer program.  The final unmount is optional.  This is to keep
tract of CodeWarrior license requirements as people install CW from a common
server.

Though I (think) am a perl'er, I am still new to the Mac and have only written
a handfull of applescripts (all from MacPerl).  The problem is that on our 7.5
OS, the chooser does not seem to be applescriptable.  Is this true?  If it is
applescriptable, any pointers to how to figure out how?

I have been to ftp://ftp.scriptweb.com/pub/ but do not understand what 'OSAX'
is (it has something called MountVolumes).  Is MountVolumes a scripting
addition (that one can place in the applescript addition folder)?

Any real pointers are greatly appreciated.  I would like to do this from
MacPerl and not from MPW.

thanks,
-sandy

p.s.  for everyone's pains, I have included below a more robust version of a
piece of code I emailed out a couple weeks ago regarding a version of a CONFIG
initialization routine for cross mac/nt/unix perl4 coding.  It has a couple bug
fixes and enhancements (as I have learned more about perl on the NT).  Please
note that this is for perl4 as there are probably (as the email indicated) more
elagant ways to do this for perl5.

CONFIG: {
    if ($MacPerl'Version) {    #' are we in MacPerl
        $mac=1; $unix=0; $nt=0;
        $pd = ':';              # use this in pathname pattern matching (mac)
        $MacQuitLevel = 0;      # quit level: 0 - don't quit after script
                                # 1 - quit if in run time
                                # 2 - always quit
                                # 3 - quit if this is the first script since running perl
        # get startup volume
        require "StandardFile.pl";   # includes GUSI
        $ENV{'HOME'} = &MacPerl'MakePath(scalar(&MacPerl'Volumes()));
        ($macdisk) = $ENV{'HOME'} =~ m/([^:]+)/;  # startup disk - no colon
        $ENV{'PWD'} = `pwd`;   # set env var to current working dir
        chop($ENV{'PWD'});     # get rid of the return at the end
        # customise these as required
        $default_mac_creator = 'SANS';
        $default_mac_type    = 'TEXT';
        $ENV{'PATH'} = "";
        $ENV{'USER'} = `hostname`;
        chop($ENV{'USER'});
        $whoami = $ENV{"USER"} || "Nobody";
    }
    elsif ($] !~ /NT/) {
        # unix
        $unix=1; $mac=0; $nt=0;
        $pd = '/';
        # set a path that works for both SystemV and BSD for now (customize when needed)
        $ENV{'PATH'} = "/usr/atria/bin:/usr/local/bin:/usr/sbin:/usr/bsd:/sbin:/usr/bin:/bin:/usr/ucb:/etc:/usr/etc:/usr/5bin";
        $whoami = $ENV{"USER"} || (getpwuid($<))[0] || "Nobody";
        # sanity check...
        die "Initialization script (CONFIG) failed - unix/nt confusion\n"
            if ((! -e "/usr") ||        # unix environs have a /usr
                # yuck - some NT shells uppercase comspec and some
                # capitalize it...
                (($tmp = $ENV{'COMSPEC'}) && ($tmp =~ /^[a-zA-Z]:\\/) && (-e $tmp)) ||
                (($tmp = $ENV{'ComSpec'}) && ($tmp =~ /^[a-zA-Z]:\\/) && (-e $tmp)));
    }
    else {
        # nt
        $nt=1; $unix=0; $mac=0;
        # perl on NT still wants the directory separator to be "/"
        # some NT shells want it to be "/" likewise; however, cmd.exe
        # may want it to be "\" - be careful...
        $pd = '/';
        # for the NT, path is ; separated and includes drive letters...
        # for example: $ENV{'PATH'} = "h:/atria/bin;c:/mksnt;t:/coretools/bin";
        # need to set PWD - requires either mks or csh to be installed...
        $ENV{'PWD'} = `pwd`;
        chop($ENV{'PWD'});
        $whoami = $ENV{"USER"} || $ENV{"USERNAME"} || "Nobody";
        # sanity check...
        die "Initialization script (CONFIG) failed - nt/unix confusion\n"
            # do not check for /usr here - on the NT checking for (-e "/usr")
            # checks for "/usr" on the current drive - multi-rooted file systems
            unless ((($tmp = $ENV{'COMSPEC'}) && ($tmp =~ /^[a-zA-Z]:\\/) && (-e $tmp)) ||
                    (($tmp = $ENV{'ComSpec'}) && ($tmp =~ /^[a-zA-Z]:\\/) && (-e $tmp)));
    }

    # handy to have these around for cross-platform work (different ascii line terminators)
    $EOL{"unix"} = "\012";              # \n
    $EOL{"mac"}  = "\015";              # \r
    $EOL{"pc"} = "\015\012";            # \r\n
}