Is there any way to execute (and obtain the results of) AppleScript code from python without using the osascript
command-line utility or appscript (which I don\'t r
You can use the PyObjC bridge:
>>> from Foundation import *
>>> s = NSAppleScript.alloc().initWithSource_("tell app \"Finder\" to activate")
>>> s.executeAndReturnError_(None)
PyPI is your friend...
http://pypi.python.org/pypi/py-applescript
Example:
import applescript
scpt = applescript.AppleScript('''
on run {arg1, arg2}
say arg1 & " " & arg2
end run
on foo()
return "bar"
end foo
on Baz(x, y)
return x * y
end bar
''')
print(scpt.run('Hello', 'World')) #-> None
print(scpt.call('foo')) #-> "bar"
print(scpt.call('Baz', 3, 5)) #-> 15