home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 May / maximum-cd-2010-05.iso / DiscContents / boxee-0.9.20.10711.exe / system / python / Lib / plat-mac / terminalcommand.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-07-20  |  1.5 KB  |  44 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.4)
  3.  
  4. '''terminalcommand.py -- A minimal interface to Terminal.app.
  5.  
  6. To run a shell command in a new Terminal.app window:
  7.  
  8.     import terminalcommand
  9.     terminalcommand.run("ls -l")
  10.  
  11. No result is returned; it is purely meant as a quick way to run a script
  12. with a decent input/output window.
  13. '''
  14. import time
  15. import os
  16. from Carbon import AE
  17. from Carbon.AppleEvents import *
  18. TERMINAL_SIG = 'trmx'
  19. START_TERMINAL = '/usr/bin/open /Applications/Utilities/Terminal.app'
  20. SEND_MODE = kAENoReply
  21.  
  22. def run(command):
  23.     '''Run a shell command in a new Terminal.app window.'''
  24.     termAddress = AE.AECreateDesc(typeApplSignature, TERMINAL_SIG)
  25.     theEvent = AE.AECreateAppleEvent(kAECoreSuite, kAEDoScript, termAddress, kAutoGenerateReturnID, kAnyTransactionID)
  26.     commandDesc = AE.AECreateDesc(typeChar, command)
  27.     theEvent.AEPutParamDesc(kAECommandClass, commandDesc)
  28.     
  29.     try:
  30.         theEvent.AESend(SEND_MODE, kAENormalPriority, kAEDefaultTimeout)
  31.     except AE.Error:
  32.         why = None
  33.         if why[0] != -600:
  34.             raise 
  35.         
  36.         os.system(START_TERMINAL)
  37.         time.sleep(1)
  38.         theEvent.AESend(SEND_MODE, kAENormalPriority, kAEDefaultTimeout)
  39.  
  40.  
  41. if __name__ == '__main__':
  42.     run('ls -l')
  43.  
  44.