Skip to main content
Participant
November 9, 2022
Answered

Need to bypass Action error in Photoshop CC script

  • November 9, 2022
  • 3 replies
  • 1505 views

Hi,

I have a problem running a recorded Action I created in Photoshop CC that stops when one of the Commands within the Action cannot be executed on any one image in a group the Action is meant to process as a batch.
The Action does the following: it selects all pixels that are of a pre-defined color using the Color Range command. Then it calls the Inverse (selection) command to select all other pixels that are not of the pre-defined color and Deletes them leaving on the Layer only the pixels that have the required color. When the Action completes these commands, it then Saves and Closes the open file and proceeds to the next. If any of the images that are being processed by the Action does not have pixels that have the pre-defined color the Action is seeking to Select, the Action stops and a pop-up window appears with the message: "The command "Color Range" is not currently available" with a "Continue" and a "Stop" buttons.

 

 

I want the Action to continue even if there are no pixels of that color to be selected. The Action should simply ignore this condition and proceed to process the next image in the group. Does anyone know how to bypass the pop-up with the "Continue" and "Stop" buttons? Any advice would be kindly appreciated as this forces me to click "Continue" every time the pop-up appears and the batch processing is no longer automated.

I tried using a Javascript (*.jsx) called from Photoshop to call the Action and try to catch the error using try-catch but it does not work because the error occurs within the Action within Photoshop and not on the Javascript itself so try-catch does not see it.

I will appreciate any suggestions on how to handle this condition during Action processing.

Thanks!

Panoramik

 

 

This topic has been closed for replies.
Correct answer Stephen Marsh

You can try the following script. You can record the script into an Action and use the Automate/Batch command.

 

You will need to change the parameters for the fuzziness, luminance, a, b values as needed in line #3.

 

#target photoshop

colorRange(25, 50, 0, 0);

try {
    app.activeDocument.selection.bounds;
    activeDocument.selection.invert();
	activeDocument.selection.clear();
	activeDocument.close(SaveOptions.SAVECHANGES);
} catch (e) {
    activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}

function colorRange(fuzziness, luminance, a, b) {
	var s2t = function (s) {
		return app.stringIDToTypeID(s);
	};
	var descriptor = new ActionDescriptor();
	var descriptor2 = new ActionDescriptor();
	descriptor.putInteger(s2t("fuzziness"), fuzziness);
	descriptor2.putDouble(s2t("luminance"), luminance);
	descriptor2.putDouble(s2t("a"), a);
	descriptor2.putDouble(s2t("b"), b);
	descriptor.putObject(s2t("minimum"), s2t("labColor"), descriptor2);
	descriptor.putInteger(s2t("colorModel"), 0);
	executeAction(s2t("colorRange"), descriptor, DialogModes.NO);
}

 

  1. Copy the code text to the clipboard
  2. Open a new blank file in a plain-text editor (not in a word processor)
  3. Paste the code in
  4. Save the text file as .txt
  5. Rename the file extension from .txt to .jsx
  6. Install or browse to the .jsx file to run (see below):

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html#Photoshop

3 replies

Bojan Živković11378569
Community Expert
Community Expert
November 10, 2022

" The Action should simply ignore this condition and proceed to process the next image in the group."

 

When mentioning condition, there are conditional steps in actions but you can not use them in that way to prevent dialogue when command is not available. There are limited set of conditions so you can not use them for case when some color is not present on image.

PECourtejoie
Community Expert
Community Expert
November 10, 2022

@Bojan Živković11378569 This would be a nice suggestion for the Conditionals Feature request that @Stephen Marsh recently posted.

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
November 10, 2022

You can try the following script. You can record the script into an Action and use the Automate/Batch command.

 

You will need to change the parameters for the fuzziness, luminance, a, b values as needed in line #3.

 

#target photoshop

colorRange(25, 50, 0, 0);

try {
    app.activeDocument.selection.bounds;
    activeDocument.selection.invert();
	activeDocument.selection.clear();
	activeDocument.close(SaveOptions.SAVECHANGES);
} catch (e) {
    activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}

function colorRange(fuzziness, luminance, a, b) {
	var s2t = function (s) {
		return app.stringIDToTypeID(s);
	};
	var descriptor = new ActionDescriptor();
	var descriptor2 = new ActionDescriptor();
	descriptor.putInteger(s2t("fuzziness"), fuzziness);
	descriptor2.putDouble(s2t("luminance"), luminance);
	descriptor2.putDouble(s2t("a"), a);
	descriptor2.putDouble(s2t("b"), b);
	descriptor.putObject(s2t("minimum"), s2t("labColor"), descriptor2);
	descriptor.putInteger(s2t("colorModel"), 0);
	executeAction(s2t("colorRange"), descriptor, DialogModes.NO);
}

 

  1. Copy the code text to the clipboard
  2. Open a new blank file in a plain-text editor (not in a word processor)
  3. Paste the code in
  4. Save the text file as .txt
  5. Rename the file extension from .txt to .jsx
  6. Install or browse to the .jsx file to run (see below):

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html#Photoshop

Participant
November 18, 2022

Thank you for the kind suggestion and your effort. I will try this approach.

Stephen Marsh
Community Expert
Community Expert
November 19, 2022

@panoramiks59063652 - Let me know how you go.

Mylenium
Legend
November 9, 2022

You can suppress all dialogs in the action settings, but if there is a "real" issue that prevents the action from working it will still stop / pause. Menu commands should be referenced in the script itself, not the action and then you can control their Options and dialogs and implement some error handling so the execution doesn't stop.

 

Mylenium 

PECourtejoie
Community Expert
Community Expert
November 10, 2022

Hi, @Mylenium talks about the second column in the actions panel: https://helpx.adobe.com/uk/photoshop/using/actions-actions-panel.html#about_actions_and_the_actions_panel

But unfortunately, I do not think that it works for the error messages.