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…
Test #2
Drag the script file to the area of the open document.
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.
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.
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.