| Mac-Carbon documentation | Contained in the Mac-Carbon distribution. |
Mac::AppleEvents - Macintosh Toolbox Interface to the Apple Event Manager
use Mac::AppleEvents;
Access to Inside Macintosh is essential for proper use of these functions. Explanations of terms, processes and procedures are provided there. Any attempt to use these functions without guidance can cause severe errors in your machine, including corruption of data. You have been warned.
A boolean.
A boolean True value.
A boolean False value.
A string.
A 16 bit integer.
A 32 bit integer.
An unsigned 32 bit integer.
A single precision floating point number.
A double precision floating point number.
An extended double precision floating point number.
A 64 bit number.
An Apple event list.
An Apple event record.
An Apple event.
A file specification record.
A file alias record.
An enumeration literal (4 byte character).
An Apple event type (4 byte character).
An application launch parameter record.
A property keyword (4 byte character).
A keyword (4 byte character).
An Edition Manager section handle.
An arbitrary value.
An application signature (4 byte character).
A QuickDraw rectangle.
A fixed point value.
A PPC Toolbox session ID.
A target ID record.
A process serial number.
No data.
The direct object parameter.
Error number.
Error string.
Process serial number.
Transaction ID.
Return ID.
Event class.
Event ID.
Destination address.
List of optional keywords.
Timeout limit.
Interaction level.
Event source address.
List of mandatory keywords not used.
Original source address.
Install handler before dispatching.
Enable/Disable OSL.
Number of processes recording AppleEvents.
Apple Event Manager version.
Core Suite Event class.
Open application without documents.
Open documents.
Print documents.
Quit application.
Apple event answer event.
Launched application has ended.
Apple event sendMode flags.
Apple event priority values.
Recording events.
Special values for return ID, transaction ID, and timeout.
Options for AEResumeTheCurrentEvent().
An array of application-wide event handlers.
$AppleEvent{"aevt", "odoc"} = \&OpenDocument;
An arrary of system-wide event handlers.
AEDesc is a Perl package that encapsulates an Apple Event Descriptor. It uses the OO methods of Perl5 to make building and parsing data structures easier.
Create a new Apple event descriptor. Sets the type and data to TYPE (default is 'null'), and HANDLE or DATA (default is empty).
$desc = new AEDesc("aevt", $event);
Return the type from the AEDesc structure. If TYPE is present, make it the new type.
Return the data from the AEDesc structure. If HANDLE is present, make it the new data.
Warning: If using Mac OS X, you must dispose of the result on your own. This is because in Mac OS, we returned the handle from the AEDesc itself, but now we must return a copy. So in Mac OS we could do:
print $desc->data->get;
Now we must do:
my $handle = $desc->data; print $handle->get; $handle->dispose;
Normally, you don't want to call data directly anyway, and you would
use get instead.
Return the data of the AEDesc structure in a smartly unpacked way.
Dispose the AEDesc.
AEKeyDesc is a Perl package that encapsulates an Apple event keyword. It uses the OO methods of Perl5 to make building and parsing data structures easier.
Creates a new Apple event keyword descriptor. Sets the keyword, type and data to KEY (default is zero), TYPE (default is 'null'), and HANDLE or DATA (default is empty).
Return the keyword of the AEKeyDesc structure. If KEY is present, make it the new keyword.
Return the type from the AEKeyDesc structure. If TYPE is present, make it the new type.
Return the data from the AEKeyDesc structure. If HANDLE is present, make it the new data.
Return the contents in a smartly unpacked way.
Dispose the underlying AEDesc.
Written by Matthias Ulrich Neeracher <neeracher@mac.com>, documentation by Bob Dalgleish <bob.dalgleish@sasknet.sk.ca>. Currently maintained by Chris Nandor <pudge@pobox.com>.
| Mac-Carbon documentation | Contained in the Mac-Carbon distribution. |
use strict; package Mac::AppleEvents; use vars '$VERSION'; $VERSION = '1.32';
BEGIN { sub typeBoolean () { 'bool' } sub typeChar () { 'TEXT' } sub typeSMInt () { 'shor' } sub typeInteger () { 'long' } sub typeSMFloat () { 'sing' } sub typeFloat () { 'doub' } sub typeLongInteger () { 'long' } sub typeShortInteger () { 'shor' } sub typeLongFloat () { 'doub' } sub typeShortFloat () { 'sing' } sub typeExtended () { 'exte' } sub typeComp () { 'comp' } sub typeMagnitude () { 'magn' } sub typeAEList () { 'list' } sub typeAERecord () { 'reco' } sub typeAppleEvent () { 'aevt' } sub typeTrue () { 'true' } sub typeFalse () { 'fals' } sub typeAlias () { 'alis' } sub typeEnumerated () { 'enum' } sub typeType () { 'type' } sub typeAppParameters () { 'appa' } sub typeProperty () { 'prop' } sub typeFSS () { 'fss ' } sub typeKeyword () { 'keyw' } sub typeSectionH () { 'sect' } sub typeWildCard () { '****' } sub typeApplSignature () { 'sign' } sub typeQDRectangle () { 'qdrt' } sub typeFixed () { 'fixd' } sub typeSessionID () { 'ssid' } sub typeTargetID () { 'targ' } sub typeProcessSerialNumber () { 'psn ' } sub typeNull () { 'null' } # registry sub typeAEText () { 'tTXT' } sub typeArc () { 'carc' } sub typeBest () { 'best' } sub typeCell () { 'ccel' } sub typeClassInfo () { 'gcli' } sub typeColorTable () { 'clrt' } sub typeColumn () { 'ccol' } sub typeDashStyle () { 'tdas' } sub typeData () { 'tdta' } sub typeDrawingArea () { 'cdrw' } sub typeElemInfo () { 'elin' } sub typeEnumeration () { 'enum' } sub typeEPS () { 'EPS ' } sub typeEventInfo () { 'evin' } sub typeFinderWindow () { 'fwin' } sub typeFixedPoint () { 'fpnt' } sub typeFixedRectangle () { 'frct' } sub typeGraphicLine () { 'glin' } sub typeGraphicText () { 'cgtx' } sub typeGroupedGraphic () { 'cpic' } sub typeInsertionLoc () { 'insl' } sub typeIntlText () { 'itxt' } sub typeIntlWritingCode () { 'intl' } sub typeLongDateTime () { 'ldt ' } sub typeISO8601DateTime () { 'isot' } sub typeLongFixed () { 'lfxd' } sub typeLongFixedPoint () { 'lfpt' } sub typeLongFixedRectangle () { 'lfrc' } sub typeLongPoint () { 'lpnt' } sub typeLongRectangle () { 'lrct' } sub typeMachineLoc () { 'mLoc' } sub typeOval () { 'covl' } sub typeParamInfo () { 'pmin' } sub typePict () { 'PICT' } sub typePixelMap () { 'cpix' } sub typePixMapMinus () { 'tpmm' } sub typePolygon () { 'cpgn' } sub typePropInfo () { 'pinf' } sub typePtr () { 'ptr ' } sub typeQDPoint () { 'QDpt' } sub typeQDRegion () { 'Qrgn' } sub typeRectangle () { 'crec' } sub typeRGB16 () { 'tr16' } sub typeRGB96 () { 'tr96' } sub typeRGBColor () { 'cRGB' } sub typeRotation () { 'trot' } sub typeRoundedRectangle () { 'crrc' } sub typeRow () { 'crow' } sub typeScrapStyles () { 'styl' } sub typeScript () { 'scpt' } sub typeStyledText () { 'STXT' } sub typeSuiteInfo () { 'suin' } sub typeTable () { 'ctbl' } sub typeTextStyles () { 'tsty' } sub typeTIFF () { 'TIFF' } sub typeVersion () { 'vers' } sub typeUnicodeText () { 'utxt' } sub typeStyledUnicodeText () { 'sutx' } sub typeUTF8Text () { 'utf8' } sub typeEncodedString () { 'encs' } sub typeCString () { 'cstr' } sub typePString () { 'pstr' } sub typeMeters () { 'metr' } sub typeInches () { 'inch' } sub typeFeet () { 'feet' } sub typeYards () { 'yard' } sub typeMiles () { 'mile' } sub typeKilometers () { 'kmtr' } sub typeCentimeters () { 'cmtr' } sub typeSquareMeters () { 'sqrm' } sub typeSquareFeet () { 'sqft' } sub typeSquareYards () { 'sqyd' } sub typeSquareMiles () { 'sqmi' } sub typeSquareKilometers () { 'sqkm' } sub typeLiters () { 'litr' } sub typeQuarts () { 'qrts' } sub typeGallons () { 'galn' } sub typeCubicMeters () { 'cmet' } sub typeCubicFeet () { 'cfet' } sub typeCubicInches () { 'cuin' } sub typeCubicCentimeter () { 'ccmt' } sub typeCubicYards () { 'cyrd' } sub typeKilograms () { 'kgrm' } sub typeGrams () { 'gram' } sub typeOunces () { 'ozs ' } sub typePounds () { 'lbs ' } sub typeDegreesC () { 'degc' } sub typeDegreesF () { 'degf' } sub typeDegreesK () { 'degk' } # new ... document and arrange later # there's more, incl. stuff for SOAP, that we may include later sub typeSInt16 () { 'shor' } sub typeSInt32 () { 'long' } sub typeUInt32 () { 'magn' } sub typeSInt64 () { 'comp' } sub typeIEEE32BitFloatingPoint () { 'sing' } sub typeIEEE64BitFloatingPoint () { 'doub' } sub type128BitFloatingPoint () { 'ldbl' } sub typeDecimalStruct () { 'decm' } sub typeFSRef () { 'fsrf' } sub typeFileURL () { 'furl' } sub kAEShowPreferences () { 'pref' } sub typeApplicationURL () { 'aprl' } sub typeKernelProcessID () { 'kpid' } sub typeMachPort () { 'port' } sub typeApplicationBundleID () { 'bund' } sub keyAcceptTimeoutAttr () { 'actm' }
sub keyDirectObject () { '----' } sub keyErrorNumber () { 'errn' } sub keyErrorString () { 'errs' } sub keyProcessSerialNumber () { 'psn ' } sub keyTransactionIDAttr () { 'tran' } sub keyReturnIDAttr () { 'rtid' } sub keyEventClassAttr () { 'evcl' } sub keyEventIDAttr () { 'evid' } sub keyAddressAttr () { 'addr' } sub keyOptionalKeywordAttr () { 'optk' } sub keyTimeoutAttr () { 'timo' } sub keyInteractLevelAttr () { 'inte' } sub keyEventSourceAttr () { 'esrc' } sub keyMissedKeywordAttr () { 'miss' } sub keyOriginalAddressAttr () { 'from' } sub keyPreDispatch () { 'phac' } sub keySelectProc () { 'selh' } sub keyAERecorderCount () { 'recr' } sub keyAEVersion () { 'vers' }
sub kCoreEventClass () { 'aevt' } sub kAEOpenApplication () { 'oapp' } sub kAEOpenDocuments () { 'odoc' } sub kAEPrintDocuments () { 'pdoc' } sub kAEQuitApplication () { 'quit' } sub kAEAnswer () { 'ansr' } sub kAEApplicationDied () { 'obit' }
sub kAENoReply () { 0x00000001 } sub kAEQueueReply () { 0x00000002 } sub kAEWaitReply () { 0x00000003 } sub kAENeverInteract () { 0x00000010 } sub kAECanInteract () { 0x00000020 } sub kAEAlwaysInteract () { 0x00000030 } sub kAECanSwitchLayer () { 0x00000040 } sub kAEDontReconnect () { 0x00000080 } sub kAEWantReceipt () { 0x00000200 } sub kAEDontRecord () { 0x00001000 } sub kAEDontExecute () { 0x00002000 } sub kAEInteractWithSelf () { 0 } sub kAEInteractWithLocal () { 1 } sub kAEInteractWithAll () { 2 }
sub kAENormalPriority () { 0x00000000 } sub kAEHighPriority () { 0x00000001 }
sub kAEStartRecording () { 'reca' } sub kAEStopRecording () { 'recc' } sub kAENotifyStartRecording () { 'rec1' } sub kAENotifyStopRecording () { 'rec0' } sub kAENotifyRecording () { 'recr' }
sub kAutoGenerateReturnID () { -1 } sub kAnyTransactionID () { 0 } sub kAEDefaultTimeout () { -1 } sub kNoTimeOut () { -2 }
sub kAENoDispatch () { 0 } sub kAEUseStandardDispatch () { 0xFFFFFFFF } sub kAEDoNotIgnoreHandler () { 0x00000000 } sub kAEIgnoreAppPhacHandler () { 0x00000001 } sub kAEIgnoreAppEventHandler () { 0x00000002 } sub kAEIgnoreSysPhacHandler () { 0x00000004 } sub kAEIgnoreSysEventHandler () { 0x00000008 } sub kAEIngoreBuiltInEventHandler () { 0x00000010 } sub kAEDontDisposeOnResume () { 0x80000000 } sub kAEUnknownSource () { 0 } sub kAEDirectCall () { 1 } sub kAESameProcess () { 2 } sub kAELocalProcess () { 3 } sub kAERemoteProcess () { 4 } sub kAEDataArray () { 0 } sub kAEPackedArray () { 1 } sub kAEHandleArray () { 2 } sub kAEDescArray () { 3 } sub kAEKeyDescArray () { 4 } # more more more! sub kAEAND () { 'AND ' } sub kAEOR () { 'OR ' } sub kAENOT () { 'NOT ' } sub kAEFirst () { 'firs' } sub kAEMiddle () { 'midd' } sub kAELast () { 'last' } sub kAEAny () { 'any ' } sub kAEAll () { 'all ' } sub kAENext () { 'next' } sub kAEPrevious () { 'prev' } sub keyAEDesiredClass () { 'want' } sub keyAEContainer () { 'from' } sub keyAEForm () { 'form' } sub keyAEKeyData () { 'seld' } sub keyAERangeStart () { 'star' } sub keyAERangeStop () { 'stop' } sub keyAEObject () { 'kobj' } sub keyAEPosition () { 'kpos' } sub kAEBefore () { 'befo' } sub kAEAfter () { 'afte' } sub kAEBeginning () { 'bgng' } sub kAEEnd () { 'end ' } sub formAbsolutePosition () { 'indx' } sub formRelativePosition () { 'rele' } sub formTest () { 'test' } sub formRange () { 'rang' } sub formPropertyID () { 'prop' } sub formName () { 'name' } sub formUniqueID () { 'ID ' } sub typeObjectSpecifier () { 'obj ' } sub typeObjectBeingExamined () { 'exmn' } sub typeCurrentContainer () { 'ccnt' } sub typeToken () { 'toke' } sub typeAbsoluteOrdinal () { 'abso' } sub typeRangeDescriptor () { 'rang' } sub typeLogicalDescriptor () { 'logi' } sub typeCompDescriptor () { 'cmpd' } sub keyAECompOperator () { 'relo' } sub keyAELogicalTerms () { 'term' } sub keyAELogicalOperator () { 'logc' } sub keyAEObject1 () { 'obj1' } sub keyAEObject2 () { 'obj2' } sub kAEGreaterThan () { '> ' } sub kAEGreaterThanEquals () { '>= ' } sub kAEEquals () { '= ' } sub kAELessThan () { '< ' } sub kAELessThanEquals () { '<= ' } sub kAEBeginsWith () { 'bgwt' } sub kAEEndsWith () { 'ends' } sub kAEContains () { 'cont' } } BEGIN { use Exporter (); use DynaLoader (); use Mac::Memory; use vars qw(@ISA @EXPORT %AppleEvent %SysAppleEvent); @ISA = qw(Exporter DynaLoader); @EXPORT = qw( AECreateDesc AECoerce AECoerceDesc AEDisposeDesc AEDuplicateDesc AECreateList AECountItems AEPut AEPutDesc AEGetNthDesc AEDeleteItem AEPutParam AEPutParamDesc AEGetParamDesc AEDeleteParam AEGetAttributeDesc AEPutAttribute AEPutAttributeDesc AECreateAppleEvent AESend AEResetTimer AESuspendTheCurrentEvent AEResumeTheCurrentEvent AEGetTheCurrentEvent AESetTheCurrentEvent AEGetInteractionAllowed AESetInteractionAllowed AEInstallEventHandler AERemoveEventHandler AEGetEventHandler AEManagerInfo AEBuild AEBuildParameters AEBuildAppleEvent AEPrint AEDescToSubDesc AEGetSubDescType AEGetSubDescBasicType AESubDescIsListOrRecord AEGetSubDescData AESubDescToDesc AECountSubDescItems AEGetNthSubDesc AEGetKeySubDesc %AppleEvent %SysAppleEvent typeBoolean typeChar typeInteger typeFloat typeLongInteger typeShortInteger typeLongFloat typeShortFloat typeExtended typeComp typeMagnitude typeAEList typeAERecord typeAppleEvent typeTrue typeFalse typeAlias typeEnumerated typeType typeAppParameters typeProperty typeFSS typeKeyword typeSectionH typeWildCard typeApplSignature typeQDRectangle typeFixed typeSessionID typeTargetID typeProcessSerialNumber typeNull typeAEText typeArc typeBest typeCell typeClassInfo typeColorTable typeColumn typeDashStyle typeData typeDrawingArea typeElemInfo typeEnumeration typeEPS typeEventInfo typeFinderWindow typeFixedPoint typeFixedRectangle typeGraphicLine typeGraphicText typeGroupedGraphic typeInsertionLoc typeIntlText typeIntlWritingCode typeLongDateTime typeISO8601DateTime typeLongFixed typeLongFixedPoint typeLongFixedRectangle typeLongPoint typeLongRectangle typeMachineLoc typeOval typeParamInfo typePict typePixelMap typePixMapMinus typePolygon typePropInfo typePtr typeQDPoint typeQDRegion typeRectangle typeRGB16 typeRGB96 typeRGBColor typeRotation typeRoundedRectangle typeRow typeScrapStyles typeScript typeStyledText typeSuiteInfo typeTable typeTextStyles typeTIFF typeVersion typeUnicodeText typeStyledUnicodeText typeUTF8Text typeEncodedString typeCString typePString typeMeters typeInches typeFeet typeYards typeMiles typeKilometers typeCentimeters typeSquareMeters typeSquareFeet typeSquareYards typeSquareMiles typeSquareKilometers typeLiters typeQuarts typeGallons typeCubicMeters typeCubicFeet typeCubicInches typeCubicCentimeter typeCubicYards typeKilograms typeGrams typeOunces typePounds typeDegreesC typeDegreesF typeDegreesK typeSInt16 typeSInt32 typeUInt32 typeSInt64 typeIEEE32BitFloatingPoint typeIEEE64BitFloatingPoint type128BitFloatingPoint typeDecimalStruct typeFSRef typeFileURL kAEShowPreferences typeApplicationURL typeKernelProcessID typeMachPort typeApplicationBundleID keyAcceptTimeoutAttr keyDirectObject keyErrorNumber keyErrorString keyProcessSerialNumber keyTransactionIDAttr keyReturnIDAttr keyEventClassAttr keyEventIDAttr keyAddressAttr keyOptionalKeywordAttr keyTimeoutAttr keyInteractLevelAttr keyEventSourceAttr keyMissedKeywordAttr keyOriginalAddressAttr keyPreDispatch keySelectProc keyAERecorderCount keyAEVersion kCoreEventClass kAEOpenApplication kAEOpenDocuments kAEPrintDocuments kAEQuitApplication kAEAnswer kAEApplicationDied kAENoReply kAEQueueReply kAEWaitReply kAENeverInteract kAECanInteract kAEAlwaysInteract kAECanSwitchLayer kAEDontReconnect kAEWantReceipt kAEDontRecord kAEDontExecute kAENormalPriority kAEHighPriority kAEStartRecording kAEStopRecording kAENotifyStartRecording kAENotifyStopRecording kAENotifyRecording kAutoGenerateReturnID kAnyTransactionID kAEDefaultTimeout kNoTimeOut kAENoDispatch kAEUseStandardDispatch kAEDoNotIgnoreHandler kAEIgnoreAppPhacHandler kAEIgnoreAppEventHandler kAEIgnoreSysPhacHandler kAEIgnoreSysEventHandler kAEIngoreBuiltInEventHandler kAEDontDisposeOnResume kAEInteractWithSelf kAEInteractWithLocal kAEInteractWithAll kAEUnknownSource kAEDirectCall kAESameProcess kAELocalProcess kAERemoteProcess kAEDataArray kAEPackedArray kAEHandleArray kAEDescArray kAEKeyDescArray AEPutKey AEPutKeyDesc AEGetKeyDesc kAEAND kAEOR kAENOT kAEFirst kAEMiddle kAELast kAEAny kAEAll kAENext kAEPrevious keyAEDesiredClass keyAEContainer keyAEForm keyAEKeyData keyAERangeStart keyAERangeStop keyAEObject keyAEPosition kAEBefore kAEAfter kAEBeginning kAEEnd kAEReplace formAbsolutePosition formRelativePosition formTest formRange formPropertyID formName formUniqueID typeObjectSpecifier typeObjectBeingExamined typeCurrentContainer typeToken typeAbsoluteOrdinal typeRangeDescriptor typeLogicalDescriptor typeCompDescriptor keyAECompOperator keyAELogicalTerms keyAELogicalOperator keyAEObject1 keyAEObject2 kAEGreaterThan kAEGreaterThanEquals kAEEquals kAELessThan kAELessThanEquals kAEBeginsWith kAEEndsWith kAEContains ); } bootstrap Mac::AppleEvents; package Mac::AppleEvents::EventHandler; BEGIN { import Mac::AppleEvents; use Carp; } sub TIEHASH { my ($package,$sys) = @_; my($me) = bless {SYS => $sys}; return $me; } sub ParseKey { my($key) = @_; return (substr($key, 0, 4), substr($key, -4)); } sub FETCH { my($sys,$key) = @_; my(@keys) = ParseKey $key; my ($handler, $refcon) = AEGetEventHandler(@keys, $sys->{SYS}); return wantarray ? ($handler,$refcon) : $handler; } sub STORE { my($sys,$key,$handler,$refcon) = @_; my(@keys) = ParseKey $key; $refcon = $key unless defined $refcon; AEInstallEventHandler(@keys, $handler, $refcon, $sys->{SYS}) || die; } sub DELETE { my($sys,$key) = @_; my(@keys) = ParseKey $key; AERemoveEventHandler(@keys, $sys->{SYS}); } sub DESTROY { my($sys) = @_; undef %{$sys}; } sub FIRSTKEY { croak "Mac::AppleEvents::EventHandler::FIRSTKEY is not implemented" } sub NEXTKEY { croak "Mac::AppleEvents::EventHandler::NEXTKEY is not implemented" } sub EXISTS { croak "Mac::AppleEvents::EventHandler::EXISTS is not implemented" } sub CLEAR { croak "Mac::AppleEvents::EventHandler::CLEAR is not implemented" } package Mac::AppleEvents;
tie %AppleEvent, q(Mac::AppleEvents::EventHandler), 0; tie %SysAppleEvent, q(Mac::AppleEvents::EventHandler), 1; my(%constant) = ( "true" => 1, "fals" => 0, "null" => "", ); package AEDesc;
BEGIN { use Mac::Types; } sub new { my($package, $type, $data) = @_; $data = "" unless defined($data); my $return; if (ref($data) ne "Handle") { $return = _new($package, $type, new Handle($data)); } else { $return = _new(@_); } return $return; } sub get () { my($desc) = @_; my($type) = $desc->type; if (exists($constant{$type})) { return $constant{$type}; } else { my $handle = $desc->data; my $return = $handle->get; $handle->dispose unless $^O eq 'MacOS'; if (defined($return) && exists($MacUnpack{$type})) { return MacUnpack($type, $return); } return $return; } } sub dispose { Mac::AppleEvents::AEDisposeDesc($_[0]); } package AESubDesc; BEGIN { use Mac::Types; import Mac::AppleEvents; } sub get () { my($desc) = @_; my($type) = AEGetSubDescType($desc); if (exists($constant{$type})) { return $constant{$type}; } elsif (exists($MacUnpack{$type})) { return MacUnpack($type, AEGetSubDescData($desc)); } else { my($aedesc, $res) = AESubDescToDesc($desc); $res = AEPrint($aedesc); AEDisposeDesc($aedesc); return $res; } } package AEKeyDesc;
sub new { my($package, $key, $type, $data) = @_; $data = "" unless defined($data); my $return; if (ref($data) ne "Handle") { $return = _new($package, $key, $type, new Handle($data)); } else { $return = _new(@_); } return $return; } sub dispose { Mac::AppleEvents::AEDisposeDesc($_[0]->desc); } *AEKeyDesc::get = *AEDesc::get{CODE}; package AEStream; sub new { my($package) = shift @_; if (!scalar(@_)) { Open(); } elsif (scalar(@_) == 1) { OpenEvent(@_); } else { CreateEvent(@_); } }
1; __END__