[Pythonmac-SIG] Re: Pythonmac-SIG Digest, Vol 5, Issue 36

Michael J. Barber mjb at uma.pt
Mon Sep 29 07:44:30 EDT 2003


On Friday, Sep 26, 2003, at 17:02 Europe/Lisbon, Dinu Gherman wrote:

> I'm sorry, but I won't have the time for doing the appropriate
> research first, so I have to ask quickly: has anyone a short
> sample for doing something like running a Python script that
> either calls an existing Applescript or does the same thing
> via OSA-whatever to run an app like SnapZ Pro X, say, and tell
> it to make a screenshot of some window, say, maybe even using
> some parameters...?
>

If you don't want to mess around with gensuitemodule, just open a pipe 
to osascript. You can either give your AppleScript to osascript as 
strings, or as a file name. Here's a little example using strings:

MACUNIXSCRIPT = """osascript -e 'return POSIX path of "%s"'"""
UNIXMACSCRIPT = """osascript -e 'return (POSIX file "%s") as string'"""

import os

def mac2unix(mpath):
     return os.popen(MACUNIXSCRIPT % mpath).readline()[:-1]

def unix2mac(upath):
     return os.popen(UNIXMACSCRIPT % upath).readline()[:-1]

Hope that helps,
Michael




More information about the Pythonmac-SIG mailing list