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

David Hughes dfh at forestfield.co.uk
Fri Nov 5 11:17:03 EST 2004


aleaxit at yahoo.com (Alex Martelli) wrote 
> has <has.temp2 at virgin.net> wrote:
> 
> > > For example, in Python in a Nutshell, Alex Martelli shows how you can
> > > run a Windows (notepad.exe) or Unix-like (/bin/vim) text editor using
> > >       os.spawnv(os.P_WAIT, editor, [textfile])
> > > But how would you call the OS X text editor /Applications/TextEdit.app
> > > - which appears to be a whole directory inside /Applications?
> > 
> > Using os.system to execute open is pretty simple, as other folks have
> > pointed out.
> 
> ...but doesn't do the P_WAIT: just like using open at the Terminal
> prompt, it immediately continues with your code even as TextEdit is
> starting up.  The idea of that snippet is to let the user edit a
> textfile for configuration, while until the user is done editing, then
> read the textfile etc etc.  And it works file on the Mac with vi too.
> 
> But apparently the P_WAIT is not implemented in the Mac version of
> Python like on the Windows version -- to *WAIT* until the app is done
> before continuing.  So, it looks as if one will have to put in more
> complicated code in that case:-(.

I don't know if that will be possible. The reason for my original
query was that I want to fire up an independent help viewer from an
application - both of which will be bundle-built. In fact, I *don't*
want to implement a wait, but I do want to use Popen from the
subprocess module to launch the viewer - so that I can use its poll()
method to check if it is already running should another launch be
requested, and also kill it on exit from the main application. But,
unlike Windows, poll() always returns a completion code of zero,
instead of None, even though the process is still running.

David



More information about the Python-list mailing list