Skip navigation.
 
mlRe: python scripting support
FROM : has
DATE : Sat May 17 23:12:59 2008

Georg Seifert wrote:

> I want wo be able to make my program scriptable. Most important with
> python.
>
> My program is written in ObjectC in XCode 3
>
> I have read lots of stuff in the net.
> What is the better possibility:
>
> 1) make it scriptable with AppleScript and use the Python/Applescript
> bridge or
> 2) embed it (with the python framework) and use "Py_Initialize();" and
> "static PyMethodDef EmbMethods[] = {"
>
> to 1:
> - it is possible to use more than on scripting languages (appleScript,
> python, javascript)


The following languages are practical options for controlling 
applications via Apple events: AppleScript, Perl (via Mac::Glue) and 
Python, Ruby, and ObjC (via appscript or Scripting Bridge). 
(JavaScriptOSA is academic since nobody uses it.)

OTOH, if your application needs to call functions in scripts, the only 
languages available as full OSA components are AppleScript and 
JavaScriptOSA. There's also PyOSA which is mostly functional, but it's 
a developer release and I wouldn't recommend it for production use.


> - it integrates in the system
>
> to 2:
> - I have to wrap up my classes (I didn’t found any example doing this
> with ObjectC classes, only C++)


Piece of cake with PyObjC. See <http://pyobjc.sourceforge.net>, and 
ask on the PythonMac-SIG mailing list for further advice <http://mail.python.org/mailman/listinfo/pythonmac-sig
>.


> - I can have a tighter integration in my program


OSA gives reasonable integration, though the coupling is still looser 
(good for flexibility, at least in theory; not so good for efficiency 
since all data is passed by copy).

> - the program can’t be remote controlled (as with apple script)


Embedding an interpreter doesn't prevent you adding an Apple event API 
at a later date. And don't forget there are other IPC options you 
could use, e.g. Distributed Objects. Maybe not as popular for desktop 
integration, but still quite usable (e.g. DO can be used fro ObjC or 
any language with an ObjC bridge - Perl, Python, Ruby, etc).


> Does anyone has some pros/cons for both approaches?


In addition to the above: Apple event IPC is a well established 
standard (pro), but a bit fiddly to implement well (con). An embedded 
interpreter will be simple to add (pro for you), but your users may or 
not appreciate being required to use one particular language (possible 
con).


If you want a specific recommendation, provide more information about 
the nature of the application and what scripters will do with it.

HTH

has
--
Control AppleScriptable applications from Python, Ruby and ObjC:
http://appscript.sourceforge.net

Related mailsAuthorDate
mlpython scripting support Georg Seifert May 17, 17:16
mlRe: python scripting support has May 17, 23:12
mlRe: python scripting support John C. Daub May 17, 23:47
mlRe: python scripting support has May 18, 11:56
mlRe: python scripting support John C. Daub May 18, 13:06
mlRe: python scripting support Georg Seifert May 18, 13:56
mlRe: python scripting support has May 18, 22:47
mlRe: python scripting support John C. Daub May 19, 00:34