1 """terminalcommand.py -- A minimal interface to Terminal.app.
3 To run a shell command in a new Terminal.app window:
6 terminalcommand.run("ls -l")
8 No result is returned; it is purely meant as a quick way to run a script
9 with a decent input/output window.
13 # This module is a fairly straightforward translation of Jack Jansen's
14 # Mac/OSX/PythonLauncher/doscript.m.
20 from Carbon
.AppleEvents
import *
24 START_TERMINAL
= "/usr/bin/open /Applications/Utilities/Terminal.app"
25 SEND_MODE
= kAENoReply
# kAEWaitReply hangs when run from Terminal.app itself
29 """Run a shell command in a new Terminal.app window."""
30 termAddress
= AE
.AECreateDesc(typeApplSignature
, TERMINAL_SIG
)
31 theEvent
= AE
.AECreateAppleEvent(kAEMiscStandards
, kAEActivate
,
32 termAddress
, kAutoGenerateReturnID
,
36 theEvent
.AESend(SEND_MODE
, kAENormalPriority
,
39 if why
[0] != -600: # Terminal.app not yet running
41 os
.system(START_TERMINAL
)
43 theEvent
.AESend(SEND_MODE
, kAENormalPriority
,
46 theEvent
= AE
.AECreateAppleEvent(kAECoreSuite
, kAEDoScript
, termAddress
,
47 kAutoGenerateReturnID
, kAnyTransactionID
)
48 commandDesc
= AE
.AECreateDesc(typeChar
, command
)
49 theEvent
.AEPutParamDesc(kAECommandClass
, commandDesc
)
50 theEvent
.AESend(SEND_MODE
, kAENormalPriority
, kAEDefaultTimeout
)
53 if __name__
== "__main__":