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

[MacPerl] Apple Events and OSAX



I was going to ask this of the list, but then figured it out.  So I will
share my findings.

#------------------------------------------------------------------------
Alright, I do this when I want to send an AppleEvent to an app:

$st = 'core';
$ev = 'Clos';
$ap = 'Arch';
$be = AEBuildAppleEvent($st,$ev,typeApplSignature,$ap,0,0,'') || die $^E;
AESend($be, kAEWaitReply) || die $^E;

This will close all open Anarchie windows.  Here is the Frontier info on
this command:

on closeall () { Çclose all the windows
        return (appleEvent (Arch.id, 'core', 'Clos'))}

#------------------------------------------------------------------------
Now, how do I send an AE using an OSAX?  Say, I want to disconnect my PPP
connection.  Here is the info:

on pppDisconnect () { ÇCloses a PPP connection
        return (appleEvent (@PPP Commands.code.AEVTnetwRAdc, 'netw', 'RAdc'))}

So I do this:

$st = 'netw';
$ev = 'RAdc';
$ap = 'MACS';  #send command to the Finder

And boom!  I'm disconnected.


#------------------------------------------------------------------------
BTW, I am going to be releasing an OT/PPP module next week or the week
after.  I have to figure out what to name it.  I am thinking
Mac::System::OT_PPP.  Any thoughts?

Now that I think about it ... this could open up lots of room for further
modules like Volume or whatever.  For example, I just whipped up this
little script to change screen depth.  Would we want to have a separate
Mac::System::Monitors module?  Or should we have one larger module to
handle all of these types of events, and the module could simply be updated
periodically to include new stuff?

Need some input here ...

#------------------------------------------------------------------------
package Monitor;
use Mac::AppleEvents;
sub setdepth {
 $depth = shift;
 $mon = shift;
 $col = shift;
 $be = AEBuildAppleEvent('gtqp','dpth',typeApplSignature,$ap,0,0,'') || die $^E;
 AEPutParamDesc($be,'dept',(AEBuild($depth)))    if (defined $depth);
 AEPutParamDesc($be,'devc',(AEBuild($mon)))      if (defined $mon);
 AEPutParamDesc($be,'CoLr',(AEBuild($col)))      if (defined $col);
 AESend($be, kAEWaitReply) || die $^E;
}
package main;
&Monitor::setdepth(8,0,0);  #change first monitor to 8-bit greyscale

#================================================================
Chris Nandor                                      pudge@pobox.com
PGP Key 1024/B76E72AD                           http://pudge.net/
Keyfingerprint = 08 24 09 0B CE 73 CA 10  1F F7 7F 13 81 80 B6 B6