summaryrefslogtreecommitdiffstats
path: root/Mac/Lib/test/tell.py
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>1996-03-18 14:21:15 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>1996-03-18 14:21:15 (GMT)
commitbb653772f5a74b18ac34f005b6b5bb8295e81eb3 (patch)
tree168575a910fcd3b71cfb9b52a4a0f56ee540e2a6 /Mac/Lib/test/tell.py
parent0f7af3f79544a5859bfd4aa3ed4e31eb6d439952 (diff)
downloadcpython-bb653772f5a74b18ac34f005b6b5bb8295e81eb3.zip
cpython-bb653772f5a74b18ac34f005b6b5bb8295e81eb3.tar.gz
cpython-bb653772f5a74b18ac34f005b6b5bb8295e81eb3.tar.bz2
Oops... I Inadvertently lost their cvs files...
Diffstat (limited to 'Mac/Lib/test/tell.py')
-rw-r--r--Mac/Lib/test/tell.py63
1 files changed, 63 insertions, 0 deletions
diff --git a/Mac/Lib/test/tell.py b/Mac/Lib/test/tell.py
new file mode 100644
index 0000000..74e0ca0
--- /dev/null
+++ b/Mac/Lib/test/tell.py
@@ -0,0 +1,63 @@
+# (Slightly less) primitive operations for sending Apple Events to applications.
+# This could be the basis of a Script Editor like application.
+
+from AE import *
+from AppleEvents import *
+import aetools
+import types
+
+class TalkTo:
+ def __init__(self, signature):
+ """Create a communication channel with a particular application.
+
+ For now, the application must be given by its 4-character signature
+ (because I don't know yet how to do other target types).
+ """
+ if type(signature) != types.StringType or len(signature) != 4:
+ raise TypeError, "signature should be 4-char string"
+ self.target = AECreateDesc(typeApplSignature, signature)
+ self.send_flags = kAEWaitReply
+ self.send_priority = kAENormalPriority
+ self.send_timeout = kAEDefaultTimeout
+ def newevent(self, code, subcode, parameters = {}, attributes = {}):
+ event = AECreateAppleEvent(code, subcode, self.target,
+ kAutoGenerateReturnID, kAnyTransactionID)
+ aetools.packevent(event, parameters, attributes)
+ return event
+ def sendevent(self, event):
+ reply = event.AESend(self.send_flags, self.send_priority,
+ self.send_timeout)
+ parameters, attributes = aetools.unpackevent(reply)
+ return reply, parameters, attributes
+
+ def send(self, code, subcode, parameters = {}, attributes = {}):
+ return self.sendevent(self.newevent(code, subcode, parameters, attributes))
+
+ def activate(self):
+ # Send undocumented but easily reverse engineered 'activate' command
+ self.send('misc', 'actv')
+
+
+# This object is equivalent to "selection" in AppleScript
+# (in the core suite, if that makes a difference):
+get_selection = aetools.Property('sele', None)
+
+# Test program. You can make it do what you want by passing parameters.
+# The default gets the selection from Quill (Scriptable Text Editor).
+
+def test(app = 'quil', suite = 'core', id = 'getd', arg = get_selection):
+ t = TalkTo(app)
+ t.activate()
+ if arg:
+ dict = {'----': arg}
+ else:
+ dict = {}
+ reply, parameters, attributes = t.send(suite, id, dict)
+ print reply, parameters
+ if parameters.has_key('----'): print "returns:", str(parameters['----'])
+
+
+test()
+# So we can see it:
+import sys
+sys.exit(1)