Rajanikanth Jammalamadaka wrote:

Could some tell me what would be the appscript equivalent of the
following applescript?

tell application "SomeApplication"
        activate
        open "some file"
        delay 300
        quit
end tell

ASTranslate <http://appscript.sourceforge.net/tools.html> is your friend. While it won't necessarily produce production-ready code, it will give you a pretty good idea of the equivalent syntax for each application command you send from AppleScript.

The only bit it won't translate is the 'delay' command, as that's a scripting addition command, not an application command, and ASTranslate only does the latter. You need to use the osax module for that and translate it yourself.

Anyway, with a bit of tidying your code should look something like this:

from appscript import *
import osax

someapp = app('SomeApplication')
stdadditions = osax.ScriptingAddition()

someapp.activate()
someapp.open(mactypes.Alias('/path/to/somefile'))
stdadditions.delay(300)
someapp.quit()



Also, is it possible to call apple scripts from appscript?


Sure. For a specific recommendation, you'll need to say more about what it is you need to do, but here are the options (note: these will work for both AS source code and compiled script files):

1. Invoke the osascript command-line tool via os.command() or subprocess.Popen. It's a crude, lowest-common-denominator approach and a real pain for passing complex values such as lists and dates since everything has to go as UTF8 text, but it avoids any extra dependencies.

2. Use StandardAdditions' 'run script' command via the osax module. Since the osax module is built on appscript, the AppleScript's parameters and results will be converted between Python and Ruby types automatically, although you are still limited to calling 'run' handlers.

3. Use the osascript module included in the appscript package. This is a high-level Python wrapper around most of the OSA API, allowing you to load the AppleScript component into your process and call an AppleScript's handlers directly (with help from the aem module). Main disadvantage is that it isn't documented, so you'll need to grok the API from the module's source code.

4. Use Cocoa's NSAppleScript or OSAKit APIs via PyObjC. Main disadvantage of this approach is that you don't get the same level of type bridging that you do with #2 or #3 above unless you use objc- appscript's AEMCodecs class, which again means another dependency.


HTH

has
--
Control AppleScriptable applications from Python, Ruby and ObjC:
http://appscript.sourceforge.net

_______________________________________________
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig

Reply via email to