Running scripts via drag-and-drop

AiScripts
3 min readNov 1, 2022

--

Ways to quickly run scripts in Illustrator that are not installed in the scripts folder:

  • Menu File → Scripts → Other Script…
  • The drag-and-drop method is to drag a script file from a folder in Explorer (Windows) or Finder (Mac) to an Adobe Illustrator window.

For future examples, let’s refresh our memory that scripts in Illustrator since CS6 can run actions through the app.doScript() method. This is convenient for those who find it easier to write down a set of operations so that they don’t have to code their ExtendScript counterpart. You can also use actions to apply commands that are not available in scripting language (example: Make Compound Shape).

// Play an action from the Actions Palette
app.doScript(“Action”, “Set”);

In most cases, a drag-and-drop script will work as intended. But 10 years in CS6-CC 2023 versions, there is a limited bug handling the script if dragged to the “wrong” area of the program window.

Let’s make an action and a short script that selects objects of each artboard and rotates them 180 degrees through the action (Transform → Rotate…).

//@target illustrator
(function() {
var doc = app.activeDocument;
for (var i = 0; i < doc.artboards.length; i++) {
doc.artboards.setActiveArtboardIndex(i);
doc.selectObjectsOnActiveArtboard();
app.doScript("ScriptAction", "ScriptSet");
selection = null;
redraw();
}
})();

Test #1

Run the script viaFile → Scripts → Other Script…

The redraw() command updates the contents of the program window

Test #2

Drag the script file to the area of the open document.

Action without logging errors, didn’t work on the first object

Test #3

And now let’s drag and drop the script file into the documents tabs area. The nuance is that the tab mode Preferences → User Interface → Open Documents As Tabs must be enabled.

In Windows OS, the script can be dragged above the tabs and onto the menu bar

Conclusions

Scripts containing action calls that the user quickly drags to the document window may not execute correctly. If the script sequentially selects objects and applies an action to them, it won’t work on the first selected object, but it will handle all the others.

So far, the problem is found in scripts that use actions with the commands from the Transform menu: Move, Rotate, Reflect, Scale, Shear.

Transform Each, which is also in the Transform menu, works correctly in any variant

You cannot predict whether other commands in the actions will work or scripts without actions will work if you drag and drop a file onto the “wrong” area of the document. That’s why it’s more reliable to run the script through menus or third-party launchers, or to remember to drag-n-drop it to the open document panel.

Vote for a solution to this problem on Illustrator Uservoice.

--

--

AiScripts

Sergey Osokin. Product Illustrator, Icon Designer, Script Developer (Ai, Ps). Writing about bugs and tricks in Adobe Illustrator scripts