使用Atom运行Adobe Illustrator CC 2017脚本报错求助
That error (-2741) almost always boils down to quoting/escaping issues when passing your JSX script through osascript from Atom's process-palette. Unlike ESTK or running the script directly in Illustrator, the command line layer adds extra syntax rules that can break your script if not handled properly. Here's how to fix it:
Step 1: Avoid Inlining Your Script in the osascript Command
The biggest culprit is trying to pass your entire JSX script as a string in the -e argument. Even small scripts can have quotes, newlines, or special characters that osascript misinterprets. Instead, save your script as a .jsx file and tell Illustrator to run it directly:
Use this command format in process-palette:
osascript -e 'tell application "Adobe Illustrator" to do script file "'"$PWD/your-script.jsx"'"'
$PWDuses your current Atom working directory to find the script (make sure your script is in that folder).- The nested quoting (
'"'and'"') ensures the path is correctly passed as a string to the AppleScript command.
Step 2: Escape Special Characters If You Must Inline
If you really need to run a short snippet inline, double-check all quotes and escape them properly:
- If your JSX uses double quotes (
"), wrap theosascript -econtent in single quotes ('), and escape any single quotes in your script with\'. - Example of an inline script with escaped quotes:
osascript -e 'tell application "Adobe Illustrator" to do script "alert(\'Hello from Atom!\');"'
Step 3: Verify Process-Palette Configuration
Make sure your process-palette command is formatted correctly:
- Don't split the
osascriptcommand across multiple lines unless you escape each line break with a backslash (\). - Ensure there are no extra spaces or unclosed quotes in the command string.
Step 4: Test with a Minimal Script
To rule out issues in your actual script, create a simple test .jsx file:
// test.jsx alert("Test successful!");
Run this with the file-based command from Step 1. If it works, the problem is in your original script's handling of characters that clash with command-line quoting.
Why does this work in ESTK/Illustrator but not Atom? Because ESTK directly communicates with Illustrator's scripting engine without going through the command line, so it doesn't have to deal with osascript's string parsing rules.
内容的提问来源于stack exchange,提问作者Bob Haslett

