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

Dan Sommers me at privacy.net
Fri Nov 5 06:37:29 EST 2004


On Fri, 5 Nov 2004 08:41:31 +0100,
aleaxit at yahoo.com (Alex Martelli) wrote:

> has <has.temp2 at virgin.net> wrote:

>> replacement. Much improved, though unfinished, AE support is available
>> from my site:
>> 
>> http://freespace.virgin.net/hamish.sanderson/appscript.html
>    ...
>> from appscript import *
>> app('TextEdit.app').open(FSSpec(pathToFile))

> OK, but how does one handle the *waiting*, so as to proceed only when
> TextEdit is done editing that document?

> "Spawning an external editor and waiting until the user is done using it
> before proceeding" is an important architectural pattern (well examined
> and analyzed in Raymond's "Art of Unix Programming", like many others).

Tty based Unix programs, yes; modern GUIs, no.  The usual parent-child
relationship between application and editor is nowhere to be found these
days.  Consider this scenario:

    1.  The application requests that Mac OS launch TextEdit and that
        TextEdit edit the given file.

        TextEdit starts (or maybe TextEdit was already running) and
        opens the document (or maybe the document was already open).
        The appliction neither knows nor cares about either of those
        details.

    2.  In any event (pun intended), the user edits the file, and maybe
        even saves it once or twice just in case there's a crash, and
        ponders the configuration before committing to it.

    3.  The user is distracted by, for example, Software Update (which
        is very annoying, but it happens), and attends to that matter.
        It could be a printer failure, or new email, or anything that
        causes the user to start working in another application.

    4.  While Software Update is thrashing, the user remembers that the
        configuration file is open but has already been saved, and
        closes it by clicking on its window's dimmed close button.
        TextEdit processes the event and closes the window without
        further ado.

At which point does the application know that the user is finished
editing the file?

With vi-as-a-child-of-the-application, even if the user spawns a
subshell (and, for that matter, an entire nested X server/session), the
termination of vi is still a well-defined.

> Ideally it should be the external editor of choice for the user;
> foisting vi on poor innocent machistas just because it's easy to wait
> for THAT and hard to wait for TextEdit would seem mean;-)...

Speaking as a long time Unix hacker *and* long time Mac user, Forcing
machistas to use a text editor instead of a GUI to edit config files
would seem mean.  ;-)

Regards,
Dan

-- 
Dan Sommers
<http://www.tombstonezero.net/dan/>
Never play leapfrog with a unicorn.



More information about the Python-list mailing list