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

Doug Schwarz see at
Fri Nov 5 16:45:38 CET 2004

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

> 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 

  import subprocess
  app = "/Applications/"
  file = "myfile.txt"
  return_code = [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

I also tried

  import os
  app = "/Applications/"
  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 Schwarz
Make obvious changes to get real email address.

More information about the Python-list mailing list