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

How to create a button to run a script?

Participant ,
Sep 10, 2018 Sep 10, 2018

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

TOPICS
Scripting
2.1K
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
Adobe
Valorous Hero ,
Sep 11, 2018 Sep 11, 2018

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:

Re: Passing Variable via BridgeTalk

Re: any body knows how to add dimension to a square, circle, (geometric drawings) would you please l...

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
Participant ,
Sep 11, 2018 Sep 11, 2018

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

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
Valorous Hero ,
Sep 12, 2018 Sep 12, 2018

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.

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 ,
Sep 11, 2018 Sep 11, 2018

if all you need is running actions, you don't need a script.

Use Actions in Button Mode

buttonMode.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
Participant ,
Sep 11, 2018 Sep 11, 2018

Thank you for your answer Carlos,

You are correct but I would like to learn more about scripting as well.

Thanks

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 ,
Sep 12, 2018 Sep 12, 2018

ok that's fair, check the code in the links and post back if you need more assistance

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
LEGEND ,
Sep 20, 2018 Sep 20, 2018

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.

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
Participant ,
Sep 20, 2018 Sep 20, 2018
LATEST

Thank you rcraighead, I will give that a try, I have on Mac at work but PC at home.

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