Skip to main content
New Participant
July 30, 2021
Question

[Javascript] Getting app.executeMenuCommand("doc-color-cmyk") to work within a larger script

  • July 30, 2021
  • 1 reply
  • 487 views

I found the following code through this forum, for setting the document color mode to CMYK:
app.executeMenuCommand("doc-color-cmyk");

It works well for a document I already have open, running the above code as just a little test script.

The problem is, I am trying to run this as part of a larger script that works through a whole folder (The script does things like remove guides, remove stray points, delete empty text nodes, resize the art, etc.) When run like this, the script seems to ignore the line of code to change color mode.

I tried moving the code to the point right after the script opens each file, thinking maybe something later in my code is interfering with it, but with that it gets the same result (no effect on color mode).

Then I tried just removing everything except the parts of the script that open the file, set color mode, and save and close the file. This time it worked.

Also, I tried running the unmodified script on a folder that contained only ONE file. This also worked.

It appears to me almost as if the executeMenuCommand code needs more time to process than "regular" JavaScript commands.

Has anyone run into anything like this or have ideas for how to resolve it?



[ title changed by moderator ]

 

This topic has been closed for replies.

1 reply

m1b
Adobe Expert
July 30, 2021

You could try adding

$.sleep(1000); // 1000 milliseconds

after the menu command.

 

New Participant
July 30, 2021

Thanks for the suggestion. I may try that later, but for now, the script seems to be working. 

I'm not sure what exactly I did to resolve the issue. I did delete some comment lines but I wouldn't think that would have any impact on this. I also restarted Illustrator. Go figure.

If the problem resurfaces, I may try your idea.

New Participant
April 23, 2024

tldr;
Create a Blank file and then run the script from there.


---------

I had the same issue, adding a time out wont fix it 😞
But opening a a blank file before running the Script will.

Why i dont know but it works xD 

found the solution it in this github project: https://github.com/arx-e/pdf-to-cmyk-and-replace-rich-black