开发者

Translate AppleScript to Python appscript (`do javascript`)

开发者 https://www.devze.com 2023-03-27 23:44 出处:网络
This is the AppleScript template: tell application \"Adobe Photoshop CS5\" set theFile to alias “Application:Documents:MyFile” open theFile

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)?


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.


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)
0

精彩评论

暂无评论...
验证码 换一张
取 消