简体   繁体   English

将 AppleScript 翻译成 Python appscript (`do javascript`)

[英]Translate AppleScript to Python appscript (`do javascript`)

This is the AppleScript template:这是 AppleScript 模板:

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.我想把它翻译成 Python appscript。 Unfortunately, I cannot figure out how to translate the do javascript .不幸的是,我不知道如何翻译do javascript Any ideas?有任何想法吗?

I don't even know how to find it out.我什至不知道如何找到它。 Maybe I know AppleScript too less.也许我知道 AppleScript 太少了。 Is do a keyword?do关键字吗? Or is it a command I am sending to the application?还是我发送给应用程序的命令? Is javascript a parameter of do ? javascript是 do 的参数do Or does do javascript belong together (as a command with a space)?或者do javascript属于一起(作为带有空格的命令)?

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).我仍然不完全知道如何翻译上述内容(更一般地说:我不知道如何将任何通用 AppleScript 代码翻译为 Python appscript)。

However, for the above case, I found that there is the command do_javascript .但是,对于上述情况,我发现有命令do_javascript It doesn't seem to execute files though but rather executes the given JS code string directly.它似乎并没有执行文件,而是直接执行给定的 JS 代码字符串。

Eg, 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)

To translate generic AppleScript to appscript , use the ASTranslate tool available from the appscript web site here .要将通用AppleScript转换为appscript ,请使用此处appscript web 站点提供的ASTranslate工具。 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.由于某些应用程序的脚本定义中的怪癖和错误,它并不总是能够成功翻译,但它是一个很好的起点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM