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

If Action Exsits

Participant ,
Mar 25, 2016 Mar 25, 2016

I'm trying to write a script to run an action but need to make sure the action exists first.  This is what I came up with so far, and it does work when there is nothing in the prompt but if I spell the action wrong it gives me an illustrator error that the action is not there.  Should I use catch for this instead?

function ActionTool() {

var action = prompt('Enter Action Name', '');

var set = "MyActionSet";

    if (action == false) {

            alert("This Action does not exist.  Please try again", false);

             }

         else{ doScript( action , set ); }

}

ActionTool();

TOPICS
Scripting
634
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

Valorous Hero , Mar 28, 2016 Mar 28, 2016

Yeah you have to use try/catch to see if an error happened to see if it's missing. The thing is, you must display alerts in the userInteractionLevel (app.userInteractionLevel = UserInteractionLevel.DISPLAYALERTS;) which will make it possible to press "Stop" and create the error for the script to catch and launch your fall-back code. Otherwise, nothing will happen. The way to really make sure an action is not there is to unload it by unloading the entire set with an empty string for an action nam

...
Translate
Adobe
Valorous Hero ,
Mar 28, 2016 Mar 28, 2016

Yeah you have to use try/catch to see if an error happened to see if it's missing. The thing is, you must display alerts in the userInteractionLevel (app.userInteractionLevel = UserInteractionLevel.DISPLAYALERTS;) which will make it possible to press "Stop" and create the error for the script to catch and launch your fall-back code. Otherwise, nothing will happen. The way to really make sure an action is not there is to unload it by unloading the entire set with an empty string for an action name argument (thanks to Qwertyfly...) When you do an unload this way and the action was not there, it shall result in a catchable error - at which point you can be sure that it's not there and then you can re-load it to make sure that it's there and it's the one you want.

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 ,
Mar 30, 2016 Mar 30, 2016

Thanks V.  The action that I am running resets font sizes and stroke weights and has quite a few sets to it.  It would take to long to reload every time.  This would probably be better written in a Script but I haven't had the time to get to it.  Thanks for the feedback.  I will try and put something together with javascript.

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 ,
Mar 31, 2016 Mar 31, 2016
LATEST

As I have recently found out, that you can find ScriptUI palettes, and that they do not get destroyed by a close() command, I bet the palettes would be a good way to keep track of currently loaded actions. I could try to make something like this in the future...

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