Skip to main content
jduncan
Community Expert
Community Expert
September 20, 2023
Answered

Weird app.doScript() behavior

  • September 20, 2023
  • 1 reply
  • 2036 views

So, @Kurt Gold has been helping me sort out some bugs with my Ai Command Palette script and we've run into some odd behavior executing actions. Original Kurt, reported an action on his Windows computer wasn't running correctly when initiated via Ai Command Palette, so he shared the action with me for testing. During testing I encounterd some really odd behavior. I have detailed everything below and also included a screen recording of me trying to execute the script and action a few different ways with mixed results. Hopefully someone has an idea of what is going wrong. Thanks in advance for any help on this!

 

Odd behavior #1, his action ran just fine on my Mac computer when initiated via Ai Command Palette. To try and sort this out, I made a simple script (see below) to test only the `app.doScript()` method without all of the overhead that comes along with Ai Command Palette.

try {
  app.doScript("polygon_inside_circle", "Test Group");
} catch (e) {
  alert("Error\n" + e);
}

When ran from "File > Scripts > Other Script...", this script works fine, and the action works correctly.

 

Odd behavior #2, when I tried this simple script via the JSX Launcher plug-in (which I use daily and rarely have any issues), I get an error. So, I then tried the drag-and-drop method of running scripts by dragging the simple script file onto the artboard and it still didn't work.

 

Odd behavior #3, puzzled, I loaded the script into Ai Comand Palette, using it's script running capability, and it runs just fine.

 

So this simple script, that fires a pretty simple action isn't working consistently and I have no idea why.

 

A few notes... Kurt's action does have some localized (German) values within it, but it that doesn't seem to affect how it runs. I don't have permission from Kurt to share the action but will share it here if he is okay with that. For reference, it is only a few steps, and all simple menu commands.

 

This topic has been closed for replies.
Correct answer sttk3

Yeah, this is what is unfortunate... Since Ai Command Palette is really just a launcher/executor (in the case of actions), I have no control over how users build their actions. I literally had no idea this was even an issue. I run my own action everyday via Ai Command Palette, and have never encountered and issue since I added the feature of executing actions.


@Kurt Gold It is strange that the move dialog appears. There are several possible causes for this

 

  • The Enter key after typing a command is the cause of the move dialog
  • Another workflow created by an app or plugin (let’s define it as a caller app) that calls the Ai Command Palette is being executed
  • When the caller app executes a script, it should exit without waiting for the result, but in fact it is waiting

 

@jduncan Ideally, this case should succeed without any special tricks; it is a case that Illustrator should handle well. All we can do is to report it to UserVoice, or to make a small tweak like the one I mentioned before.

1 reply

Legend
September 20, 2023

Depending on the route used to execute the script, the position of the undo state and the state of the selection after the action is executed will change.

 

In this case, I think it is most likely due to the fact that the action is dependent on the selection state.

 

The routes are as follows

  • Execute from the script menu
  • Open the jsx file in Illustrator
  • Drop the jsx file on the document
  • Execute from do javascript
jduncan
Community Expert
jduncanCommunity ExpertAuthor
Community Expert
September 20, 2023

Thanks @sttk3! I follow what you are saying and figured that may be the case (even though I've never experienced it when testing scripts and actions)... But, the original issue was that the action works correctly on Mac but not on Windows when ran via Ai Command Palette (which just uses `app.doScript()` under the hood... So, I'm hoping someone may have an idea as to why.

m1b
Community Expert
Community Expert
September 20, 2023

Hi @jduncan, I don't think I can help with testing here because I'm also running MacOS. However, I was thinking about @sttk3's comments and wondering if there is anything you can do—before executing the script/action—to "normalize" the app state no matter which ways the command is started. I'm just hand-waving here, but wondering whether, say, executing via an idleTask will do that. Or maybe there's another way... Or maybe the problem is something else...

- Mark

 

EDIT: Sorry about the "idleTask" idea... that would only work in Indesign. I'm sleep-deprived and lost track of which forum 🥱