Re: Launching an independent Python program in a cross-platform way (including mac)



On Apr 30, 10:59 am, Kevin Walzer <k...@xxxxxxxxxxxxxxx> wrote:
[snip]

There are extension modules on the Mac for integrating Python and
AppleScript (the best one is appscript). However, if you want to limit
yourself to core Python, your best best is osascript, a system
command-tool that lets you call AppleScript code with arguments from
other programs. This can be called via os.system.

The basis syntax for doing this from Python might look something like this:

os.system('osascript -e \'tell app \"Terminal\" to activate\'')

This simply launches Terminal. Note that you have to deal with quoting
issues. The equivalent syntax from AppleScript would be:

tell app "Terminal" to activate

If you want to Terminal to run a command-line program from AppleScript,
you can do this with the "do script" command. Code to do this could look
something like this:

myscript = "python -e foo.py"
os.system('osascript -e '\tell app \"Terminal"\ to do script %s\'',
myscript)

I haven't tested this, but you get the basic idea--define the script and
command-line paramaters in a string, then pass that to
AppleScript/osascript as a variable. This code should launch Terminal,
then run the external Python script.

HTH,
Thanks. I managed to get something like this to work. Later, I'll
post it as an example to this thread so that other can use if for a
reference if needed.

André
Kevin

--
Kevin Walzer
Code by Kevinhttp://www.codebykevin.com


.



Relevant Pages

  • Re: Folder Actions on Mac OSX Leopard?
    ... have applescript call python scripts via `do shell script`. ...
    (comp.lang.python)
  • Re: applescript discussion
    ... and have been wondering if applescript might be a more ... mean or want to start a comparison of python and applescript, ... If you are just learning programming and want to learn a clean modern ... language, Python or Ruby are both excellent choices. ...
    (comp.sys.mac.system)
  • Re: Launching an independent Python program in a cross-platform way (including mac)
    ... The following seems to work correctly under Ubuntu and Windows ... ... However, if you want to limit yourself to core Python, your best best is osascript, a system command-tool that lets you call AppleScript code with arguments from other programs. ... I haven't tested this, but you get the basic idea--define the script and command-line paramaters in a string, then pass that to AppleScript/osascript as a variable. ...
    (comp.lang.python)
  • Re: applescript discussion
    ... and have been wondering if applescript might be a more ... mean or want to start a comparison of python and applescript, ... If you are just learning programming and want to learn a clean modern ... language, Python or Ruby are both excellent choices. ...
    (comp.sys.mac.system)
  • Re: Folder Actions on Mac OSX Leopard?
    ... I've been trying to figure out if it's possible to attach a Python ... script to an action via Mac OSX Leopard's File Actions system. ... monitored folder. ... I would either go with applescript all the way, ...
    (comp.lang.python)