How do you execute an OS X application (bundle) from Python?
claird at lairds.us
Fri Nov 5 19:08:04 CET 2004
In article <69cbbef2.0411041513.120fc039 at posting.google.com>,
has <has.temp2 at virgin.net> wrote:
>dfh at forestfield.co.uk (David Hughes) wrote in message
>news:<70bb9f8d.0411040250.1f4ac1a at posting.google.com>...
>> 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. The other way is to use Apple events, the standard
>high-level IPC system used by Mac GUI apps. The AE support currently
>in the standard library leaves something to be desired and is due for
>replacement. Much improved, though unfinished, AE support is available
>from my site:
>Fastest way to open a document is via the lower-level aem package
>(lower overheads, though you have to use raw AE codes):
>from aem.send import Application
>from Carbon.File import FSSpec
>Alternatively, the high-level appscript package wraps all this stuff
>in OO-like syntactic sugar and human-readable terminology (takes
>longer to initialise as it has to retrieve and parse the application
>from appscript import *
This thread's focus on editing casuistry and Mr. Sanderson's
own modesty might lead many to overlook what interesting
riches he's offering here. While his work is "unfinished",
I think it'll intrigue anyone who works with MacOS. Try it.
More information about the Python-list