1

This is the AppleScript template:

tell application "Adobe Photoshop CS5"
  set theFile to alias “Application:Documents:MyFile” open theFile
  do javascript (file <path to Emboss.jsx>) with arguments { 75,2,89 }
end tell

And I would like to translate that to Python appscript. Unfortunately, I cannot figure out how to translate the do javascript. Any ideas?

I don't even know how to find it out. Maybe I know AppleScript too less. Is do a keyword? Or is it a command I am sending to the application? Is javascript a parameter of do? Or does do javascript belong together (as a command with a space)?

ziganotschka
  • 25,866
  • 2
  • 16
  • 33
Albert
  • 65,406
  • 61
  • 242
  • 386
  • `do javascript` is probably a command to run Js code (in this case the code is in a file). You normally use this in Safari, but adobe apps also support this – Fábio Diniz Aug 15 '11 at 14:09
  • 2
    Why the close vote without even giving any comment? – Albert Aug 15 '11 at 14:41

2 Answers2

2

To translate generic AppleScript to appscript, use the ASTranslate tool available from the appscript web site here. It is not always able to successfully translate due to the quirks and bugs in the script definitions of some applications but it is a good place to start.

Ned Deily
  • 83,389
  • 16
  • 128
  • 151
1

I still don't exactly know how to translate the above (and more generally: I don't know how to translate any generic AppleScript code to Python appscript).

However, for the above case, I found that there is the command do_javascript. It doesn't seem to execute files though but rather executes the given JS code string directly.

E.g., this works:

from appscript import *
import os, sys

ps = app("Adobe Photoshop CS5")

filelist = sys.argv[1:]

jsCode = """
var g_StackScriptFolderPath = app.path + "/Presets/Scripts/" 
var runMergeToHDRFromScript = true; 
$.evalFile(g_StackScriptFolderPath + "Merge to HDR.jsx");
mergeToHDR.mergeFilesToHDR(%s, true);
""" % (repr(filelist),)

ps.do_javascript(jsCode)
Albert
  • 65,406
  • 61
  • 242
  • 386