How to create a button to run a script?
Copy link to clipboard
Copied
Hi,
I would like to create a button that stays on the screen and I can use " app.doScript()" run an action.
I would appreciate any help.
So far I found this
var dlg = new Window('dialog','Align Center');
dlg.btn = dlg.add('button',undefined,'Align Center');
dlg.btn.onClick = function(){app.doScript('AlignCenter','Align')}
dlg.show();
the problem I have with this is, after I run the script then I can't click on any other object to run the script again and I have to close it and reopen it.
Thanks
Alex
Explore related tutorials & articles
Copy link to clipboard
Copied
Unfortunately in order to have a floating panel in Illustrator, you can no longer utilize such simple and elegant lines of code to accomplish this seemingly straight-forward and simple purpose. To proceed, you must use one of two more-complicated ways: either you have to use the BridgeTalk object and keep your script all in the realm of .jsx file(s), or construct a CEP extension which will involve web-design and many files/folders/settings to ensure it's all working good.
Since you can accomplish most basic needs with a bridgetalk-enabled .jsx script, I tend to go this way before investing in creation of a real CEP extension.
The BT-panels have a special behavior of taking focus away from the document so you have to click on the app frame to bring the focus back. This could be worked around by closing the panel and re-opening it so that when it comes back it's no longer in focus though.
Check out some threads here dealing with BridgeTalk:
Copy link to clipboard
Copied
Thank you Silly-V,
I will look into BridgeTalk to see if I can put something together.
Unfortunately I can't write any codes and what I am doing is to look around and take pieces here and there from free scripts Ii find online and patch them together.
I can not take credit for any of those codes that was in my main question.
I will keep you posted if I come up with something new
Thank you again
Copy link to clipboard
Copied
With BridgeTalk, I will fully confess that in order to make the functions I use today, I had to prowl the forums for copy-paste bits which I could never have figured out myself, such as Bob Stuckey's ingenious method for disarming the passed script string of its script-breaking characters such as nextlines and comments. The function is called "BridgeTalk encode" - but before even all that it's important to know the basics and to write your own custom BT function as a string.
Check out BT examples here which show a simple alert or document action, which is how I got started. After seeing how simple functions passed this way work, then it was time to figure out how to pass complex functions and even entire scripts.
Sure BridgeTalk coding is very frustrating, but it is still a way to create a floating panel without having to create an entire CEP extension if the purpose is to simply do the same kind of things a dialog can do, but you just want it to float around.
Copy link to clipboard
Copied
if all you need is running actions, you don't need a script.
Use Actions in Button Mode
Copy link to clipboard
Copied
Thank you for your answer Carlos,
You are correct but I would like to learn more about scripting as well.
Thanks
Copy link to clipboard
Copied
ok that's fair, check the code in the links and post back if you need more assistance
Copy link to clipboard
Copied
If you're on the Mac you can use the 3d-party app, "Keyboard Maestro" to create floating button palettes that run Scripts, Actions and a whole lot more. It's drag-n-drop interface makes it easy to learn and is a great support tool for scripts.
Copy link to clipboard
Copied
Thank you rcraighead, I will give that a try, I have on Mac at work but PC at home.

