将 AppleScript 转换为 Python appscript (`do javascript`)

发布于 2024-11-30 04:15:58 字数 502 浏览 1 评论 0原文

这是 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

我想将其转换为 Python appscript。不幸的是,我不知道如何翻译do javascript。有什么想法吗?

我什至不知道如何找到它。也许我对 AppleScript 的了解太少了。 do 是关键字吗?或者这是我发送给应用程序的命令? javascriptdo 的参数吗?或者 do javascript 属于一起吗(作为带空格的命令)?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心碎的声音 2024-12-07 04:15:58

要将通用 AppleScript 转换为 appscript,请使用 appscript 网站上提供的 ASTranslate 工具 此处。由于某些应用程序的脚本定义中的怪癖和错误,它并不总是能够成功翻译,但它是一个很好的起点。

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.

奢欲 2024-12-07 04:15:58

我仍然不完全知道如何翻译上面的内容(更一般地说:我不知道如何将任何通用的 AppleScript 代码翻译为 Python appscript)。

然而,对于上面的情况,我发现有命令do_javascript。它似乎并不执行文件,而是直接执行给定的 JS 代码字符串。

例如,这有效:

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)

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文