Debugging macros which automate Illustrator with JavaScript

So I inherited a quite complex set of macros to automate some artwork generation. I can't seem to find where some illustrator artwork rotation is happening. Stepping through the macro, some Javascript is called which sends some scripting to Illustrator which in turn rotates some artwork on named layers.

In the javascript there are 4 lines of code with "rotate", in different spots with conditional statements. That is all great but when I comment out those 4 lines to try to "break" the rotation, the artwork still rotates. I've checked for some illustrator actions and nothing of the sort nor are any actions being called to perform.

Any ideas out there? Thanks

If you share the macro, it will give us a better chance to find the problem.

1 Like

See this post on how to share a macro: Share Macro to Forum from Keyboard Maestro

Problem is it is a chain of 117 macros out of a library of over 400...

Then I think the best way is for you to run the process in steps. And see when does the rotating happen.

Yep, have done that many times and narrowed it down to one JS function.

Are you OK with sharing that JS function?

Ya possibly. It is crazy though. I can change the name of that function to try to break the link to it and the artwork still rotates. It is like MacOS is sometimes linking to another file somewhere. Is there a known issue with MacOS not reading the correct file? I've search and destroyed any other copy of the function repository. I get the feeling that there is something I am missing but this function is the only one that is being called from a macro.

More likely there's something else going on, like KM telling AI to run a script which runs a script in a static file Whoop-de-doop.js -- and the rotate command is in there.

If there's a chain of 117 macros, add a KM "Display Dialog" action at the end of every 20th macro to display the numbers 1 thru 6. You can then watch for the rotation and dialog -- if rotation happens after "4" but before "5" you'll know it is somewhere in actions 81-100. Rinse and repeat until you've nailed it down to a single macro at post that.

1 Like

I don't think that is necessary. I can watch illustrator while the macros are running and step through one by one and see when it rotates. It is frustrating to know exactly which function is running right before the rotate, then try to effect some change, like setting the rotation angle to 90 instead of 45, and nothing happens to that effect in Illustrator. It is like the function is being cached or stored in memory instead of reading the script each time? Is that possible? and if it is how do I kill any behavior like that?

Difficult to say without seeing the macro.

There's a number of ways to run scripts in Illustrator from KM. If you send it "direct", eg with a KM "Execute AppleScript" action and tell application "Adobe Illustrator" to do javascript "some_javascript()" then it should do what you send. If, instead, you use a KM action to write some JavaScript to a file then tell AI to execute that file you could have problems if there are asynchronous calls or similar.

The problem is far more likely to be either in the logic of the macro or some funky Illustrator side-effect than in KM's behaviour.

I just changed it to use Applescript to run the file and same results. I commented out all rotate in the JS and I am still getting rotation in AI.

So the JavaScript that Illustrator is running is in a file? Then it is either an Illustrator, file system, or user error issue -- it almost sounds as though the file you are editing isn't the file Illustrator is running.

We have a functions file with over 100 functions.

I am calling a function in that file. I literally can change the function name in that file and the macro will still run.. the artwork will still rotate. Now there is another file that holds product data and rotation angle data. I can change the rotation angle in that file and eventually it will take into illustrator. Normal rotation is 45, and I will just tell it 90 so I can see the effect.

I'm thinking a file system problem, what kind of file system issues can come up?