【问题标题】:How To Open Files in Illustrator 2020 via AppleScript如何通过 AppleScript 在 Illustrator 2020 中打开文件
【发布时间】:2020-03-08 12:36:15
【问题描述】:

OSX 10.13.6、AI 2020、Applescript 编辑器版本 2.10 (194)、AppleScript 2.7

(认为这无关紧要,但我不准备升级操作系统,因为 NVidia 仍未发布系统使用的 TitanXP GPU 的驱动程序)。

在本次讨论中坚持使用 AppleScript。请不要提出“仅使用 JavaScript”的建议,除非您可以确认或否认 JavaScript 中也存在该问题。

我想知道 Adob​​e 是否已对其 Illustrator API 进行了更改,因为自从升级到新的 2020 版本以来,以前与早期版本的 Illustrator 一起使用的 Applescript 文件现在在通过别名引用时难以打开文件,或 posix 样式格式的变量。

InDesign 似乎没有受到影响,因为每次发生主要版本升级时,我都会在数百个 .INDD 文件上运行一个脚本,以防止下次使用它们时出现“另存为”对话框,这可能会搞砸脚本。该脚本仍然有效。还没有尝试过 Photoshop,但我使用的大部分自动化都是它们内部的“动作”形式。

经过一番研究,我认为他们可能已经修改了 HFS 支持,导致了意想不到的后果。

Illustrator 2020 可以打开由 posix 样式格式的硬编码字符串引用的文件,但无法从变量(HFS 样式别名或引用的 posix 样式字符串)打开同一个文件,即,

  set theHFSPath to "Mac HD:Users:Mac User:Documents:Illustrator:myFile.ai"
  set thePosixPath to quoted form of theHFSPath
  # i.e., '/Volumes/Mac HD/Users/Mac User/Documents/Illustrator/myFile.ai'

  Tell Application "Adobe Ilustrator"
    # Opens OK
    open POSIX file "/Volumes/Mac HD/Users/Mac User/Documents/Illustrator/myFile.ai" without dialogs

    # Crashes with "Adobe Illustrator got an error: The specified file could not be opened because it could not be found"
    open theHFSPath as alias without dialogs
    # open (theHFSPath as alias) also crashes

    # Crashes with "Adobe Illustrator got an error: File/Folder expected"
    open POSIX file thePosixPath without dialogs
    # open POSIX file (quoted form of thePosixPath)
    #    without quoting HFSPath above also crashes
  End Tell

我怀疑 Adob​​e 可能丢弃了一个处理 HFS 的低级例程,并且由于该例程失败,打开命令无法“看到”打开它的文件。

关于“管”的内容不多,但我遇到过:

http://forum.latenightsw.com/t/apple-script-for-illustrator-2020-javascript-code-was-missing/2167

不到一周前,这似乎描述了同样的问题。

还有其他人遇到过这个问题,或者知道如何解决吗?

【问题讨论】:

  • 既然你在 Hackintosh 上运行 macOS,我想任何事情都有可能发生。
  • A) 可以通过 Thunderbolt 运行外部 GPU。 B) 即使这是一个 Hackintosh,它也与新行为无关。 Applescript 的操作系统或版本都没有改变。只有 AI 不同。
  • 1. “错误”!=“崩溃”。 2. quoted form of theHFSPath 应为 POSIX path of theHFSPath。 3. 确保路径指向有效文件。 4. 尝试将 POSIX file 说明符移到 tell application… 块之外,例如set f to POSIX file "/Users/foo/myFile.ai" ; tell app "Adobe Illustrator" to open f.
  • 很确定这是崩溃,而不是编码错误。请参阅帖子中的代码。作为 POSIX 样式的硬编码字符串,它会打开。作为设置为 EXACT SAME STRING 的变量,无论是否引用,它都会崩溃。作为 HFS 样式的别名,它也会崩溃。在 AI 2019 中,它将作为别名打开 OK(显然没有引用)。在 AI 2019 中运行的相同代码和相同文件,现在在 AI 2020 中中断。
  • “Crash”表示进程异常退出。 “Adobe Illustrator 出现错误:预期的文件/文件夹”是一个错误;该过程无法执行请求的操作并告诉您。此处的区别很重要,因为如果 Illustrator/Script Editor 崩溃,那么这是应用程序本身的一个致命错误——不是你的错——你应该提交报告。 OTOH,如果 SE 在您的脚本底部显示错误消息,那要么是 AI 的 open 处理程序中的(非致命)错误,要么是您自己的 AppleScript 代码中的错误。澄清崩溃与错误有助于我们缩小原因。

标签: applescript adobe adobe-illustrator


【解决方案1】:

以下示例在 macOS 10.14.6 下运行的 AI 2020(我刚刚安装)和 CC 2017 上完全符合预期:

set alis to alias "Macintosh HD:Users:foo:test.ai" -- an existing file
tell application "Adobe Illustrator" to open alis
-- AI opens test.ai document

set furl to POSIX file "/Users/foo/test.ai"
tell application "Adobe Illustrator" to open furl
-- AI opens test.ai document

这也按预期工作(尽管 AI 的错误消息质量很差):

set furl to POSIX file "/Users/foo/xxxxx.ai" -- a non-existent file
tell application "Adobe Illustrator" to open furl
-- SE reports error "Adobe Illustrator got an error: AppleEvent handler failed." number -10000

..

但是,以下内容并不如您所愿:

set pth to "/Users/foo/test.ai"
tell application "Adobe Illustrator" to open POSIX file pth

open 命令既不会打开文件,也不会发回解释原因的错误消息。这是 AppleScript 的对象说明符的那些疯狂古怪和不直观的陷阱之一,被 AI 糟糕的错误处理弄得更加混乱。

简短说明:该脚本有效地告诉 AI 打开 POSIX file "…" of <Illustrator>,并且由于应用程序的字典不包含 POSIX file 类,因此应用程序无法解析该引用。而您需要先说POSIX file "…" of <AppleScript>,它告诉AS 建立一个POSIX file 值(它知道如何做),然后将构造的值传递给open 命令。

这就是为什么在任何 tell app… 块之外构建 aliasPOSIX filedate 等值总是一个好主意。这是一个粗略的经验法则,但很容易记住。 (最好不要把 AS 的行为想得太难,因为你只会让你的head hurt。)

--

现在,如果您在 macOS 10.15 下看到不同的行为,那么这意味着其他地方发生了变化(可能是在操作系统中),这会在其他地方造成连锁反应;如果是这种情况,请使用更多详细信息更新您的原始帖子。


[更新添加]

这些可在 AI 2020 及更早版本 (macOS 10.14.6) 上正常工作:

set f to POSIX file "/Users/foo/test.ai" -- existing file
tell application "Adobe Illustrator" to open f
-- AI opens document

set f to POSIX file "/Users/foo/test.ai" -- existing file
tell application "Adobe Illustrator" to open f with dialogs
-- AI opens document

set f to POSIX file "/Users/foo/test.ai" -- existing file
tell application "Adobe Illustrator" to open f without dialogs
-- AI opens document

set f to POSIX file "/Users/foo/xxxxxx.ai" -- non-existent file
tell application "Adobe Illustrator" to open f without dialogs
-- AI throws File Not Found error

这也适用于 AI 2020:

set f to alias "Macintosh HD:Users:foo:test.ai" -- existing file
tell application "Adobe Illustrator" to open f

然而,虽然这些在 AI 2019 上正常工作,但在 AI 2020 上,即使文件存在,它们不正确会引发 File Not Found 错误:

set f to alias "Macintosh HD:Users:foo:test.ai" -- existing file
tell application "Adobe Illustrator" to open f with dialogs
-- error "Adobe Illustrator got an error: The specified file could not be opened because it could not be found" number 9032

set f to alias "Macintosh HD:Users:foo:test.ai" -- existing file
tell application "Adobe Illustrator" to open f without dialogs
-- error "Adobe Illustrator got an error: The specified file could not be opened because it could not be found" number 9032

set f to alias "Macintosh HD:Users:foo:test.ai" -- existing file
tell application "Adobe Illustrator" to open f with options {class:open options, add to recent files:true}
-- error "Adobe Illustrator got an error: The specified file could not be opened because it could not be found" number 9032

因此,可以确认AI 2020的open命令中有一个[非崩溃] BUG,当其直接参数是别名 还给出了一个或多个位置参数。

目前,您需要通过将别名值强制为 POSIX file 值[1] 来解决此错误,然后再将其传递给 AI 2020 的 open 命令:

set f to alias "Macintosh HD:Users:foo:test.ai" -- existing file
tell application "Adobe Illustrator" to open (f as «class furl») with options {class:open options, add to recent files:true}

或者,现在可能是重新编写 AppleScript 代码以消除使用别名值并在整个过程中使用 POSIX 文件值的好时机。古老的(OSX 之前)alias 值类型早已在 macOS 的其余部分中被弃用,取而代之的是现代安全范围的书签,may be why 它突然闯入了像 AI 2020 这样的最新更新的应用程序。

唉,AppleScript 几年前被降级为维护模式,所以我怀疑 Apple 是否会彻底解决旧/新/工作/损坏文件类型的绝对混乱;它们只是您需要了解并在您自己的代码中解决的问题。 (即不要费心向 Apple 提交 AppleScript 功能请求;除非这是一个安全漏洞,否则他们可能会忽略它。)

如果您想提交有关 AI 2020 的 open 命令的 Adob​​e 错误报告,您可以这样做。不保证他们会修复它;他们可能只是告诉你同样的事情——停止传递它 [deprecated] 别名值并改用 [supported] POSIX 文件值——但至少它会记录在案,因为 WontFix 可以让用户知道它。

--

[1] 请注意,在将值强制为 POSIX 文件时,您必须写成 f as «class furl» f as POSIX file。这是由于 AS 中长期存在的缺陷,Apple 永远不会修复。

【讨论】:

  • (抱歉格式化)Foo,谢谢,这些例子,唉,没用。在多台机器上试过。将文件设置为“Users:Mac User:Documents:Illustrator:myFile.ai”(在 AI Tell 内部)失败:以别名打开文件 |失败:打开 POSIX 文件(文件的 POSIX 路径)|失败:打开 POSIX 文件(文件的 POSIX 路径的引用形式)|作品:打开“/Users/Mac User/Documents/Illustrator/myFile.ai”|这在 AI 2019 中运行良好,但 AI 2020 似乎不接受别名,或以可变形式引用 POSIX 路径。只有当 POSIX 样式的引用是硬编码时,它才会打开它们。
  • 还尝试按照 Foo 的建议将变量设置在 tell 之外。相同的响应,除非您在硬编码字符串中使用 POSIX 样式的引用,否则它会失败。
  • 您需要更加注意错误消息的内容,因为它们中的大多数都告诉您您的路径指向不存在的文件。 "Users:Mac User:Documents:Illustrator:myFile.ai" 不是有效路径(HFS 路径以卷名开头);因此,您使用该路径的所有后续示例都将失败。你只是在混淆自己。先用这个调试路径:set f to POSIX file "/Users/Mac User/Documents/Illustrator/myFile.ai" ; tell app "Finder" to exists f; Finder 确认路径有效后,将其更改为 tell app "Adobe Illustrator" to open f
【解决方案2】:

'k,问题本身似乎与 HFS 或 POSIX 路径无关。非常感谢大家的回复和cmets,仍然相信AI 2020的open命令有bug;将前往 Adob​​e 看看是否有其他人举报。

如果对路径进行硬编码,即

Tell Adobe Illustrator
   open POSIX file "/Users/Mac User/Documents/Illustrator/myFile.ai" without dialogs
End Tell

工作。

然而,事实证明,在 AI 2020 中,罪魁祸首是可选的“无对话框”参数以及对文件的别名或 POSIX 样式变量引用。

根据字典会追加一个

without dialogs

打开命令以绕过 AI 在打开文件时可能出现的任何常规对话框。

尽管这在 AI 2019 中运行良好,但它导致打开命令在 AI 2020 中崩溃,即使 AI 2020 字典仍将“对话框”显示为可选布尔参数,其语法与 2019 版本相同。

为了验证这个假设,我启动了一个仍然有 AI 2019 的旧 Mini,然后尝试:

set theFile to "Users:Mac User:Documents:Illustrator:myFile.ai"
open theFile as alias without dialogs

正如预期的那样,这工作得很好,多年来一直如此。

在 AI 2020 中,具有相同的文件引用,

open theFile as alias without dialogs

使打开命令崩溃。

删除without dialogs,它会按预期打开。

因此,目前唯一的解决方法似乎是忽略对话框参数。

希望 Adob​​e 更新他们的 AS 字典或修复错误。

保重!

【讨论】:

  • 可以确认:AI 2020 的open 命令总是在其直接参数为alias值时会抛出“File Not Found”错误并且它有一个或多个带标签的参数。这 AI 的aevt/odoc 事件处理程序中的一个实现错误;该文件确实存在,所以它应该打开。这不是一个 AI 字典错误(有趣的是,我确实找到了一个字典错误,但它无关),也不是一个崩溃错误,所以不要说它是(即 AI 之后继续正常运行)。请参阅附加到我的原始答案的额外信息(欢迎您将其包含在您向 Adob​​e 提交的错误报告中)。
  • 谢谢,Foo,我已更正:错误与崩溃。超过 5 年没有接触过有问题的代码,所以你可能也是正确的,它是 Adob​​e 已经弃用的东西。应该在我大量的空闲时间重构所有内容。 ;)
猜你喜欢
  • 1970-01-01
  • 2010-09-23
  • 2011-10-10
  • 2018-08-16
  • 1970-01-01
  • 2019-03-29
  • 1970-01-01
  • 2012-06-30
  • 1970-01-01
相关资源
最近更新 更多