Prevent to showing up an Action error dialog during execution

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

Vlad
Posts: 7
Joined: Wed May 23, 2018 9:10 am

Prevent to showing up an Action error dialog during execution

Post by Vlad »

I've spent a decent amount of time trying to handle the next thing.


I run some Action using a script and I want to prevent showing any error messages( like "Command Apply is not currently available ..." ) that could happen during the process. When an error throws I don't want to see the message but just want to show up an alert message with some text, for example, no layers have been selected or another.

I've tried using action descriptor either doAction method. Also, I tried playing with DialogModes.NO with try/catch statement but to no avail.

Is there any way to solve this problem?
Thankful in advance.
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Prevent to showing up an Action error dialog during execution

Post by Kukurykus »

What do you want to apply? If something is present that applying can be done then run that (item of that) action. Or do something else like continuing from some later action item or else nothing like stopping process. If that was for ex. 'Image/Apply Image' then you could use this:

Code: Select all

function sTT(v) {return stringIDToTypeID(v)}

function enabled() {
executeActionGet(ref).getObjectValue(sTT('menuBarInfo')).getList(sTT('submenu'))
.getObjectValue(4).getList(sTT('submenu')).getObjectValue(12).getString(sTT('enabled'))
}

function cas(v1, v2, v3, v4) {
ref1 = new ActionReference()
if (v3) ref1.putIndex(sTT('command'), v3)
function nme(v) {ref1.putName(sTT('action'), v1)}
for(i = 0; i < (arr = [a = 'action', a + 'Set' ]).length; i++) {
ref1.putName(sTT(arr[i]), arguments[i])
}
(dsc1 = new ActionDescriptor()).putReference(sTT('null'), ref1)
dsc1.putBoolean(sTT('continue'), v4 || false)
executeAction(sTT('play'), dsc1)
}

// cas('Action 4', 'Set 1') // plays all Action 1 items of Set 1
// cas('Action 4', 'Set 1', 1) // plays only item1 of Action 1 in Set 1
// cas('Action 4', 'Set 1', 1, true) // plays item 1 and all next of Action 1 in Set 1


if (enabled()) cas('Action 4', 'Set 1')
else {
cas('Action 4', 'Set 1', 1)
cas('Action 4', 'Set 1', 3, true)
}

// the above is going to check if 'Apply Image' item is enabled. if so it runs all i'Action 1' items of 'Set 1'
// if not then runs only Action 1 item 1, and then go to Action 1 item 3 to continue all others from

// that probably won't ever happen but if user turned off visibility of some menu it'll be seen as disabled

If you have CS6 EXTENDED then you can use only 'actions' function of above script. If CC 2018 - and probably some earlier - then both functions.

Something is screwed up on this forum (that noone cares of!) so we(?) can not see indentations. Better download script from attachement:

Manu and Action.rar
(951 Bytes) Downloaded 474 times

Ps. Vlad, please don't forget to check Private Message ;)
Vlad
Posts: 7
Joined: Wed May 23, 2018 9:10 am

Re: Prevent to showing up an Action error dialog during execution

Post by Vlad »

Thank you very much for your reply.

This is an interesting script, however, it doesn't solve the problem I have.

I'll try to explain more accurately what I'm trying to do.
The next example is just the example and not a real action that I have, but it will give the point.

For example, I have an action with the name "toConvert" that sits in the action set "MySet".
"toConvert" action simply converts a layer to a Smart Object.
I'm invoking action through the script. When the layer is selected it simply converts the layer into a Smart Object and all is ok. But when nothing is selected, it simply throws an error (command Apply is not currently available .. ).
What I'm trying to do is to prevent showing up any errors during the action execution, because it shows them up with two buttons "stop" and "continue". I just want an alert message that will signal me what went wrong.
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Prevent to showing up an Action error dialog during execution

Post by Kukurykus »

So you want something there wasn't designed :) Actions work independly, however might be triggered by script. Script before playing action can check if not any layer is selected then either play your actions without SmartObject command (with a method I wrote in previous post) or at all, but alerting a waring instead of no selected layer.

That's known bug regarding no layer selected in Layers panel, so when not any is selcted then Photoshop by default sees like the first was active. It only 'thinks' so as trying to do any action on will cause an error. I do not know you want such workaround, that will check at least one layer is selected before playing action, but if not you can use other, like replacing that Smart Object action command with short script that will behave accordingly to ecountered situation. So your script would run action which specific command will be inserted as another short situational script (saved to 'Presets / Scripts' folder of your Photoshop):

Code: Select all

#target photoshop
$.level = 0; try{executeAction(stringIDToTypeID('newPlacedLayer'), undefined, DialogModes.NO)}catch(err){alert(err.message)}

This way you will get a message what happened, and after you click okey button, an action will be continued (untill there wasn't something that needed presence of Smart Object i.e. in next item(s)). btw I just realised I did not sent you last time private message, so I am doing it now :)