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



I would like to see this as a command along with something to open web
pages.. Just one command instead of trying to figure out all the
different op systems. look forward to seeing your code

https://sourceforge.net/projects/dex-tracker


On Apr 30, 9:40 am, André <andre.robe...@xxxxxxxxx> wrote:
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- Hide quoted text -

- Show quoted text -- Hide quoted text -

- Show quoted text -


.



Relevant Pages

  • Re: Launching an independent Python program in a cross-platform way (including mac)
    ... Just one command instead of trying to figure out all the ... AppleScript. ... then run the external Python script. ...
    (comp.lang.python)
  • Re: AppleScripting
    ... Paul Berkowitz wrote: ... >> I'm a beginner AppleScript programmer, and I'm looking for a way to ... I need a command that opens the Labels ... So to stop the script from waiting I introduced a deliberate ...
    (microsoft.public.mac.office.word)
  • Re: Command-line equivalent of "Create archive of..."
    ... Wrap that in an applescript to get the path_to_item and item_name of your ... dragged object (get the POSIX path) and you should be set. ... do shell script "touch bam.baz" ... command gets 'forgotten' after the first call to do shell script ends. ...
    (uk.comp.sys.mac)
  • Re: English-like Python
    ... The big advantage of AppleScript syntax is that it makes it easy to ... command name, a command name followed by a property/constant/variable ... With more conventional language syntaxes, ...
    (comp.lang.python)
  • Re: Command line printing
    ... through an applescript, the following script would work (this is just code ... By the way - command line is not an option. ... so that margin warnings won't stop the script. ... >> Using lpr does not work as I suspect lpr does not understand the WORD>> format. ...
    (microsoft.public.mac.office.word)