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

Re: [MacPerl] question abou



        Reply to:   RE>>[MacPerl] question about appleevent

How about just using Applescript rather than buildling the apple event?  I
don't know enough Perl to quite understand yours, but I do see that you handle
errors better than this - I haven't figured out how to get the errors back
from DoAppleScript yet.  Thank you for your example.  I can see that will be
handy.

Here's the unmount you wanted in Applescript (uses a Finder event) - the mount
came mostly from an old MacPerl digest.

#!/usr/local/bin/perl -w

use Carp;

&mount_volume ("Volume", "Server", "Genotyping", "username", "password") or
	 croak "There is no such volume or I can't mount it!\n";

&unmount_volume ("Volume");
&MacPerl'Quit(1);


#**************************************************************************
# Mounting & unmounting servers subroutines
#**************************************************************************
sub mount_volume {     
   local   ($volume, $server, $zone, $username, $password);

    ($volume, $server, $zone, $username, $password) = @_;
    unless (&MacPerl::DoAppleScript(<<_EOAS_)) {
      tell application "Finder" 
        if not exists disk \"$volume\" then #194#
          MountVolume Volume \"$volume\" Server \"$server\" Zone \"$zone\"
#194#
Username \"$username\" Password \"$password\"
      end tell
_EOAS_
    }
	   return 1;
}

sub unmount_volume {
     local  $volume;

     my ($volume) = $_[0];

     unless (&MacPerl::DoAppleScript(<<_EOAS_)) {
          tell application "Finder"
               if (list disks) contains \"$volume\" then
                    put away disk \"$volume\"
               end if
          end tell
_EOAS_
     }
}

--------------------------------------
Date: 9/16/97 10:33 AM
To: Whitney Cunha
From: Chris Nandor
At 08.06 9/16/97, Laurent Bardi wrote:
>the goal is to have a mount/umount sub under macperl
>sub mount
>{
>        local($zone,$machine,$share,$user,$password)=@_
>}
>sub unmount
>{
>        local($zone,$machine,$share)=@_
>}

Well, I couldn't figure out today how to unmount (anyone else have this?),
but here is the mounting version.

Requires the Mount Volume OSAX (Laurent has it if you can't find it online).


#!perl -wl
use strict;
use Mac::AppleEvents;

mount('PowerPudge','PowerPudge','Pudge','passwd');
sub mount {
    my($evt,@evt,%evt,$be,$rp,$er);
    die 'usage: mount(VOLUME,SERVER,USER,PASSWORD,ZONE)' if (!$_[0] ||
!$_[1]);
    %evt = (
        VOLM=>shift,    #required
        SRVR=>shift,    #required
        USER=>shift,    #optional
        PASS=>shift,    #optional
        ZONE=>shift,    #optional
    );
    foreach (keys %evt) {
        if ($evt{$_}) {
            $evt .= ",$_:TEXT(@)";
            push @evt,$evt{$_};
        }
    }
    substr($evt,0,1) = '';

    $be =
AEBuildAppleEvent('aevt','mvol',typeApplSignature,'MACS',0,0,$evt,@evt) ||
die $^E;
    $rp = AESend($be, kAEWaitReply) or die $^E;
    if (defined($er = AEGetParamDesc($rp,'errn'))) {
        warn 'Mount Volume error ', AEPrint($er);
    }
}

__END__

--
Chris Nandor             pudge@pobox.com             http://pudge.net/
%PGPKey=('B76E72AD',[1024,'0824 090B CE73 CA10  1FF7 7F13 8180 B6B6']


***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch