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
2010-08-15 21:24:42
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
2010-08-15 22:46:51
@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
2010-08-16 00:08:44
Oh, Alex, I certainly wasn't disagreeing with *you*!
Ned Deily
2010-08-16 00:51:32
@Ned, nor was I disagreeing with you (that's why I say "sure";-), so we appear to be in furious agreement;-).
Alex Martelli
2010-08-16 01:24:26