Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Floating panel to run script

Contributor ,
Jul 23, 2025 Jul 23, 2025

Hello, would be happy if someone may point out how to run a script from a floating panel button. 

below fails to be able to run the script once the button is hit. 

 

The script it is talking to runs perfectly fine on its own, but the button script is failling to call it correctly. 

 

The script says there is no document but i have one open...

 

Many thanks 

 

Smyth 

//@target illustrator
//@targetengine "persistent"
//@strict on

// Suppress warning
app.preferences.setBooleanPreference("ShowExternalJSXWarning", false);

var win = new Window('palette', 'Run Custom Script', undefined, { closeButton:true });
win.alignChildren = ['fill', 'top'];

var runBtn = win.add('button', undefined, 'Run Grids V2.jsx');
runBtn.onClick = function() {
    var scriptPath = "C:/Program Files/Adobe/Adobe Illustrator 2021/Presets/en_US/Scripts/Grids V2.jsx";
    var scriptFile = new File(scriptPath);
    if (!scriptFile.exists) {
        alert("Script not found at:\n" + scriptFile.fsName);
        return;
    }
    try {
        $.evalFile(scriptFile);
    } catch (e) {
        alert("Could not execute script:\n\n" + e);
    }
};

win.center();
win.show();

 

TOPICS
How-to , Scripting , Tools
315
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 23, 2025 Jul 23, 2025

Hi @SmythWharf, persistent floating palettes are more complicated to code than modal dialogs, because you need to communicate between Illlustrator and the palette in the same way you would communicate between Illustrator and, say, Photoshop... via BridgeTalk.

 

I wrote a demo script here showing a minimal set up. It is a palette that shows the currently selected raster item's scale and rotation. That should get you started.

- Mark

Translate
Adobe
Community Expert ,
Jul 23, 2025 Jul 23, 2025

Hi @SmythWharf, persistent floating palettes are more complicated to code than modal dialogs, because you need to communicate between Illlustrator and the palette in the same way you would communicate between Illustrator and, say, Photoshop... via BridgeTalk.

 

I wrote a demo script here showing a minimal set up. It is a palette that shows the currently selected raster item's scale and rotation. That should get you started.

- Mark

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jul 23, 2025 Jul 23, 2025

Hello, 

 

I see, I am afriad the link is not working. May this be updated.

 

Best, 

 

Smyth

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 23, 2025 Jul 23, 2025

Sorry! Fixed now.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jul 23, 2025 Jul 23, 2025

Thank you very much

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jul 23, 2025 Jul 23, 2025

#target illustrator
#targetengine main

// --------------- CONFIG ---------------
var scriptsFolder = Folder("C:/Program Files/Adobe/Adobe Illustrator 2021/Presets/en_US/Scripts");
// --------------------------------------

// Create floating panel (ScriptUI palette)
var panel = new Window('palette', 'Scripts Runner');
panel.orientation = "column";
panel.alignChildren = ["fill", "top"];

// List scripts and create buttons
if (scriptsFolder.exists) {
var scriptFiles = scriptsFolder.getFiles("*.jsx");

if (scriptFiles.length === 0) {
panel.add("statictext", undefined, "No .jsx scripts found!");
}

for (var i = 0; i < scriptFiles.length; i++) {
(function(scriptFile) {
var btn = panel.add("button", undefined, scriptFile.name);

btn.onClick = function() {
// Defensive: make sure a document is open
if (app.documents.length === 0) {
alert("No document open!");
return;
}
try {
scriptFile.open('r');
var scriptContent = scriptFile.read();
scriptFile.close();

// Use BridgeTalk for robust context
var bt = new BridgeTalk();
bt.target = "illustrator";
bt.body = scriptContent;
bt.send();
} catch (e) {
alert("Failed to run script: " + scriptFile.name + "\n\n" + e);
}
};
})(scriptFiles[i]);
}
} else {
panel.add("statictext", undefined, "Scripts folder not found!");
}

panel.center();
panel.show();

yup seems to work many thanks 

Smyth

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 23, 2025 Jul 23, 2025

Good work! 🙂

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jul 24, 2025 Jul 24, 2025

Any hints on how to run just one script form a location, I keep running into issues of scripts saying no document, when I try something, yet it is fine in the document above? 

 

Thank you 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Jul 24, 2025 Jul 24, 2025
LATEST

Oh it get's worse

when running scripts through the script runner, those scripts cannot read the xml file sitting in my documents. Running the script direcrly from Ilustrator is fine, so there is something in the script runner script which prevents the scripts it runs from seeing where it needs to see?

SmythWharf_0-1753388063187.png

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines