diff options
author | cinap_lenrek <cinap_lenrek@localhost> | 2011-05-03 11:25:13 +0000 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@localhost> | 2011-05-03 11:25:13 +0000 |
commit | 458120dd40db6b4df55a4e96b650e16798ef06a0 (patch) | |
tree | 8f82685be24fef97e715c6f5ca4c68d34d5074ee /sys/lib/python/plat-mac/terminalcommand.py | |
parent | 3a742c699f6806c1145aea5149bf15de15a0afd7 (diff) |
add hg and python
Diffstat (limited to 'sys/lib/python/plat-mac/terminalcommand.py')
-rw-r--r-- | sys/lib/python/plat-mac/terminalcommand.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/sys/lib/python/plat-mac/terminalcommand.py b/sys/lib/python/plat-mac/terminalcommand.py new file mode 100644 index 000000000..292f09c7d --- /dev/null +++ b/sys/lib/python/plat-mac/terminalcommand.py @@ -0,0 +1,47 @@ +"""terminalcommand.py -- A minimal interface to Terminal.app. + +To run a shell command in a new Terminal.app window: + + import terminalcommand + terminalcommand.run("ls -l") + +No result is returned; it is purely meant as a quick way to run a script +with a decent input/output window. +""" + +# +# This module is a fairly straightforward translation of Jack Jansen's +# Mac/OSX/PythonLauncher/doscript.m. +# + +import time +import os +from Carbon import AE +from Carbon.AppleEvents import * + + +TERMINAL_SIG = "trmx" +START_TERMINAL = "/usr/bin/open /Applications/Utilities/Terminal.app" +SEND_MODE = kAENoReply # kAEWaitReply hangs when run from Terminal.app itself + + +def run(command): + """Run a shell command in a new Terminal.app window.""" + termAddress = AE.AECreateDesc(typeApplSignature, TERMINAL_SIG) + theEvent = AE.AECreateAppleEvent(kAECoreSuite, kAEDoScript, termAddress, + kAutoGenerateReturnID, kAnyTransactionID) + commandDesc = AE.AECreateDesc(typeChar, command) + theEvent.AEPutParamDesc(kAECommandClass, commandDesc) + + try: + theEvent.AESend(SEND_MODE, kAENormalPriority, kAEDefaultTimeout) + except AE.Error, why: + if why[0] != -600: # Terminal.app not yet running + raise + os.system(START_TERMINAL) + time.sleep(1) + theEvent.AESend(SEND_MODE, kAENormalPriority, kAEDefaultTimeout) + + +if __name__ == "__main__": + run("ls -l") |