views:

55

answers:

1

The questions says it all.. (On a Mac obviously)

+2  A: 

this nice article suggests the simple solution

cmd = """osascript -e 'tell app "Finder" to sleep'"""
def stupidtrick():
    os.system(cmd)

though today you'd use the subprocess module instead of os.system, of course.

Be sure to also check page 2 of the article for many more info and options, including appscript.

Alex Martelli
If you going to do any kind of non-trivial Apple Event scripting from Python, you should be using appscript. It's well-designed, mature, and well-supported.
Ned Deily
@Ned, sure, but for such a simple, specific purpose as calling a simple bit of applescript, the "stupid trick" of `osascript -e` and `subprocess.call`, as suggested in the article's page 1 (well the article as I mentions uses the old `os.system`, but that's a detail;-) might suffice.
Alex Martelli
Oh, Alex, I certainly wasn't disagreeing with *you*!
Ned Deily
@Ned, nor was I disagreeing with you (that's why I say "sure";-), so we appear to be in furious agreement;-).
Alex Martelli