1 # The oldest AppleEvent test program.
2 # Its function has been overtaken by echo.py and tell.py.
5 from AppleEvents
import *
14 MacOS
.SchedParams(1, 0)
16 def aehandler(request
, reply
):
18 print 'request:', aetools
.unpackevent(request
)
19 param
= request
.AEGetParamDesc(keyDirectObject
, typeWildCard
)
20 if param
.type == typeAEList
:
21 n
= param
.AECountItems()
22 print 'List has', n
, 'items'
23 for i
in range(1, 1+n
):
24 type, item
= param
.AEGetNthDesc(i
, typeFSS
)
26 print 'item', i
, ':', type, item
.type, len(data
), 'bytes'
27 vol
, dir, fnlen
= struct
.unpack('hlb', data
[:7])
28 filename
= data
[7:7+fnlen
]
29 print 'vol:', vol
, '; dir:', dir, '; filename:', `filename`
30 print 'full path:', macfs
.FSSpec((vol
,dir,filename
)).as_pathname()
34 print 'param:', (param
.type, param
.data
[:20]), param
.data
[20:] and '...'
39 def passtothink(list):
40 target
= AE
.AECreateDesc(typeApplSignature
, 'KAHL')
41 event
= AE
.AECreateAppleEvent(kCoreEventClass
,
44 kAutoGenerateReturnID
,
46 aetools
.packevent(event
, {keyDirectObject
: list})
47 reply
= event
.AESend(kAENoReply | kAEAlwaysInteract | kAECanSwitchLayer
,
50 #print "Reply:", aetools.unpackevent(reply)
52 event
= AE
.AECreateAppleEvent(kCoreEventClass
,
55 kAutoGenerateReturnID
,
57 reply
= event
.AESend(kAENoReply | kAEAlwaysInteract | kAECanSwitchLayer
,
61 def unihandler(req
, rep
):
66 def quithandler(req
, rep
):
70 def corehandler(req
, rep
):
72 parameters
, attributes
= aetools
.unpackevent(req
)
73 print "event class =", attributes
['evcl']
74 print "event id =", attributes
['evid']
75 print 'parameters:', parameters
76 # echo the arguments, to see how Script Editor formats them
77 aetools
.packevent(rep
, parameters
)
79 def wildhandler(req
, rep
):
80 print 'wildcard event!'
81 parameters
, attributes
= aetools
.unpackevent(req
)
82 print "event class =", attributes
['evcl']
83 print "event id =", attributes
['evid']
84 print 'parameters:', parameters
86 AE
.AEInstallEventHandler(typeAppleEvent
, kAEOpenApplication
, aehandler
)
87 AE
.AEInstallEventHandler(typeAppleEvent
, kAEOpenDocuments
, aehandler
)
88 AE
.AEInstallEventHandler(typeAppleEvent
, kAEPrintDocuments
, aehandler
)
89 AE
.AEInstallEventHandler(typeAppleEvent
, kAEQuitApplication
, quithandler
)
90 AE
.AEInstallEventHandler(typeAppleEvent
, typeWildCard
, unihandler
)
91 AE
.AEInstallEventHandler('core', typeWildCard
, corehandler
)
92 #AE.AEInstallEventHandler(typeWildCard, typeWildCard, wildhandler)
99 ok
, e
= Evt
.WaitNextEvent(-1, 60)
102 if e
[0] == 23: # kHighLevelEvent
103 AE
.AEProcessAppleEvent(e
)
104 elif e
[0] == keyDown
and chr(e
[1]&0xff) == '.' and e
[4]&cmdKey
:
105 raise KeyboardInterrupt, "Command-Period"
109 if __name__
== '__main__':
112 print "This module is obsolete -- use echo.py or tell.py ..."