How do you execute an OS X application (bundle) from Python?

Doug Schwarz see at sig.for.address.edu
Fri Nov 5 10:45:38 EST 2004


In article <1gms4py.c7p5cjeee3clN%aleaxit at yahoo.com>,
 aleaxit at yahoo.com (Alex Martelli) wrote:

[snip]
> easily shell out), then that's going to be what we do -- until and
> unless shelling out to TextEdit or BBEdit or whatever is just as easy.


You can start-up TextEdit, edit myfile.txt and wait until TextEdit quits 
with

  import subprocess
  app = "/Applications/TextEdit.app/Contents/MacOS/TextEdit"
  file = "myfile.txt"
  return_code = subprocess.call( [app, file] )

I don't know if there's a way to detect when the file is simply closed.

The subprocess module is available from

  http://www.lysator.liu.se/~astrand/popen5/


I also tried

  import os
  app = "/Applications/TextEdit.app/Contents/MacOS/TextEdit"
  file = "myfile.txt"
  return_code = os.spawnlp(os.P_WAIT, app, "TextEdit", file)

but TextEdit never started up.  Instead I got this error message:

2004-11-05 10:32:34.586 TextEdit[9789] No Info.plist file in application 
bundle or no NSPrincipalClass in the Info.plist file, exiting


Doug

-- 
Doug Schwarz
dmschwarz&urgrad,rochester,edu
Make obvious changes to get real email address.



More information about the Python-list mailing list