Skip to main content
Known Participant
April 24, 2025
Answered

There is a problem with saving as illustrator using AppleScript

  • April 24, 2025
  • 1 reply
  • 685 views

The following is my code. It works when I use version 2023, but it fails when I use version 2024. The error message is "Cannot get document 1"

 

save aiDoc in file mynewfilepath as Illustrator ¬

with options {class:Illustrator save options, embed ICC profile:true, flatten output:preserve appearance}

 

Please help me

Correct answer hhas01

This does appear to be a bug. The error occurs when the `save` command’s `with options` parameter is a record containing a `embed icc profile` property.

 

Your command is valid but fails on AI 28.7.6 and AI 29.5 (macOS 15.3.2):

 

 

set mynewfile to "/Users/jsmith/test.ai" as POSIX file -- change this to your actual path

tell application "Adobe Illustrator"
  save document 1 in mynewfile as Illustrator with options ¬
    {class:Illustrator save options, flatten output:preserve appearance, embed icc profile:false} -- this errors!
end tell

 

 

However this works:

 

set mynewfile to "/Users/jsmith/test.ai" as POSIX file -- change this to your actual path

tell application "Adobe Illustrator"
  save document 1 in mynewfile as Illustrator with options ¬
    {class:Illustrator save options, flatten output:preserve appearance} -- this works
end tell

 

In addition, the “Can’t get document 1” error message is incorrect as the problem is the `with options` parameter, so that’s a second bug. (I’ll assume you do have at least one document open. Ironically, if you don’t, AI correctly returns an error but this time the message is “File/Folder expected” instead of “Can’t get document 1”, so that’s three bugs in the `save` command!)

 

You can file your bug report here:

 

https://illustrator.uservoice.com/

1 reply

hhas01Correct answer
Inspiring
April 24, 2025

This does appear to be a bug. The error occurs when the `save` command’s `with options` parameter is a record containing a `embed icc profile` property.

 

Your command is valid but fails on AI 28.7.6 and AI 29.5 (macOS 15.3.2):

 

 

set mynewfile to "/Users/jsmith/test.ai" as POSIX file -- change this to your actual path

tell application "Adobe Illustrator"
  save document 1 in mynewfile as Illustrator with options ¬
    {class:Illustrator save options, flatten output:preserve appearance, embed icc profile:false} -- this errors!
end tell

 

 

However this works:

 

set mynewfile to "/Users/jsmith/test.ai" as POSIX file -- change this to your actual path

tell application "Adobe Illustrator"
  save document 1 in mynewfile as Illustrator with options ¬
    {class:Illustrator save options, flatten output:preserve appearance} -- this works
end tell

 

In addition, the “Can’t get document 1” error message is incorrect as the problem is the `with options` parameter, so that’s a second bug. (I’ll assume you do have at least one document open. Ironically, if you don’t, AI correctly returns an error but this time the message is “File/Folder expected” instead of “Can’t get document 1”, so that’s three bugs in the `save` command!)

 

You can file your bug report here:

 

https://illustrator.uservoice.com/

Known Participant
April 25, 2025

Thank you very much for your help. I don't have a Facebook account, so I can't fill in the BUG. If you can, can you help me submit this BUG?

Do you know that JavaScript will also have the same problem?

Inspiring
April 25, 2025

You can create an account with your email address; you don’t need Facebook (I don’t have it either).

 

JavaScript appears to work correctly:

 

var d = app.documents[0];

var saveOptions = new IllustratorSaveOptions();
saveOptions.flattenOutput = OutputFlattening.PRESERVEAPPEARANCE;
saveOptions.embedICCProfile = true;

d.saveAs(new File('~/testjs.ai'), saveOptions);