Copy link to clipboard
Copied
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();
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
...Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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...
Find more inspiration, events, and resources on the new Adobe Community
Explore Now