How can I invoke custom Scripting Additions using Python Appscript?

290 views Asked by At

Assuming I have a new scripting addition, does appscript recognize them, and how do you invoke them using appscript?

1

There are 1 answers

0
has On

Use the osax module. Examples:

import osax

print osax.scriptingadditions() # lists installed scripting additions

standardadditions = osax.OSAX() # uses built-in StandardAdditions.osax (the default)
print standardadditions.random_number(from_=1, to=10)

satimage = osax.OSAX('Satimage') # uses 3rd-party Satimage.osax from satimage-software.com
print satimage.hypot([3, 4])

Use ASDictionary to export scripting addition terminology in appscript format.

OS X 10.6 caveat: The osax module can dynamically retrieve scripting addition terminology in 32-bit processes only. It is possible to use it in 64-bit processes if you export the terminology as a static glue module and import that, but it's fiddly. BTW, most third-party osaxen don't yet support 64-bit, so you'll need to watch for that as well.

Personally, I would try finding a native Python solution before using resorting to scripting additions as osaxen are pretty nasty anyway. YMMV.