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

Photoshop Script for randomizing paramters within the Filter Gallery

New Here ,
Mar 01, 2025 Mar 01, 2025

Copy link to clipboard

Copied

Hello Community,

 

I'm curious about Photoshop's randomization capabilities. I'm looking to batch edit a group of photos using a Photoshop action, and within that action, use filters in the Filter Gallery. Is there a way to randomize the parameter values used in a Filter gallery filter?

 

I've done some research and it looks like the best way to do this would be through the use of a script. Is anyone aware of a Photoshop script that can randomize filter parameters? I've looked within this forum and other places online for days and have been unable to find anything like this. I'm completely new to scripting so any help at all is greatly appreciated 🙂 

TOPICS
Actions and scripting , macOS

Views

201
Translate

Report

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
Community Expert ,
Mar 01, 2025 Mar 01, 2025

Copy link to clipboard

Copied

@ugonnaa21431338 

 

The easy and short answer is yes.

 

The harder and longer answer is that it depends. Your question is too generic, it comes down to specifics.

 

The Filter Gallery has six main groups.

 

Within each group there are a variable number of separate filters.

 

Each filter has different parameters, that vary in count and applicable values.

 

Finally, multiple filters and their parameters can be combined in a single pass by using the + sign to combine their results based on the order of operations

 

Bottom line is that you need to be very specific... For example:

 

* How many total filters do you wish to randomise?

 

* If there were 3 filters in total, should the selection of one of the 3 filters be randomised?

 

* Once the script runs a specific filter, is it every parameter that needs to be randomised for each filter, or are there only specific parameters within a given filter that require randomisation?

Votes

Translate

Report

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 ,
Mar 01, 2025 Mar 01, 2025

Copy link to clipboard

Copied

Here is a visual example of the how the Photocopy filter would be scripted, using fixed parameters. These fixed parameters would need to be replaced with variables from random generators.

 

photocopy.pngexpand image

 

And here is an example of how this would be scripted:

 

var photocopyRandomDetail = Math.floor(Math.random() * 24) + 1;  // Random integer between 1-24
var photocopyRandomDarken = Math.floor(Math.random() * 50) + 1;  // Random integer between 1-50
GEfc_photocopy(photocopyRandomDetail, photocopyRandomDarken);

function GEfc_photocopy(detail, darken) {
    var c2t = function (s) {
        return app.charIDToTypeID(s);
    };
    var s2t = function (s) {
        return app.stringIDToTypeID(s);
    };
    var descriptor = new ActionDescriptor();
    descriptor.putEnumerated(c2t("GEfk"), c2t("GEft"), s2t("photocopy"));
    descriptor.putInteger(s2t("detail"), detail);
    descriptor.putInteger(s2t("darken"), darken);
    executeAction(c2t("GEfc"), descriptor, DialogModes.NO);
}

 

Note: I purposely chose a simple example. Some of the filters use parameters which are not simple integers.

Votes

Translate

Report

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
New Here ,
Mar 01, 2025 Mar 01, 2025

Copy link to clipboard

Copied

Hello Stephen,

 

Thank you for the detailed image and description. I have a couple of questions on how I would adapt this code to work on another filter that uses integers.  From what I understand, it seems like this is the process to create/modify your script to work on another filter:

1.  The name of the respective filter should be entered in the following line, with the word/string "photocopy" being replaced by the name of the filter:

descriptor.putEnumerated(c2t("GEfk"), c2t("GEft"), s2t("photocopy"));

So for example, if I was using the Poster Edges filter I would replace "photocopy" with "poster edges". Is that correct?

 

2. For every parameter that takes in an integer, I need to declare the parameter/variable up top. So for example the following lines of: 

var photocopyRandomDetail = Math.floor(Math.random() * 24) + 1;  // Random integer between 1-24
var photocopyRandomDarken = Math.floor(Math.random() * 50) + 1;  // Random integer between 1-50

Would be replaced with 

var posteredgesRandomEdgeThickness = Math.floor(Math.random() * 10) + 1;  // Random integer between 1-10
var posteredgesRandomEdgeIntensity = Math.floor(Math.random() * 10) + 1;  // Random integer between 1-10
var posteredgesRandomPosterization = Math.floor(Math.random() * 6) + 1;  // Random integer between 1-6

Is this correct?

 

3. The line of 

GEfc_photocopy(photocopyRandomDetail, photocopyRandomDarken);

would be amended to the filter name and the declared variables/parameters. This would make it

GEfc_posteredges(posteredgesRandomEdgeThickness, posteredgesRandomEdgeIntensity, posteredgesRandomPosterization);

Is this correct?

 

4. The function line would need to be amended to contain all of the filters parameters. For example:

function GEfc_photocopy(detail, darken)

Would be changed to

function GEfc_posteredges(edgethickness, edgeintensity, posterization)

Is that correct?

 

5. Finally, for each parameter I would need a line inputting the random generators for each parameter. This would turn this 

    var descriptor = new ActionDescriptor();
    descriptor.putEnumerated(c2t("GEfk"), c2t("GEft"), s2t("photocopy"));
    descriptor.putInteger(s2t("detail"), detail);
    descriptor.putInteger(s2t("darken"), darken);
    executeAction(c2t("GEfc"), descriptor, DialogModes.NO)

into this

    var descriptor = new ActionDescriptor();
    descriptor.putEnumerated(c2t("GEfk"), c2t("GEft"), s2t("posteredges"));
    descriptor.putInteger(s2t("edgethickness"), edgethickness);
    descriptor.putInteger(s2t("edgeintensity"), edgeintensity);
    descriptor.putInteger(s2t("posterization"), posterization);
    executeAction(c2t("GEfc"), descriptor, DialogModes.NO)

Is this correct? In addition, how should I write the parameter names in this section? I see that in your example you made the names all lowercase. In my case where the name of the parameter in photoshop is "Edge Thickness" how should this be written in the random generator? Should it be made all lowercase with spaces removed or should I follow another convention?

 

Once again, thank you so much Stephen, you are truly a lifesaver!!!

Votes

Translate

Report

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 ,
Mar 01, 2025 Mar 01, 2025

Copy link to clipboard

Copied

Using your example of Poster Edges, here is the raw ScriptListener recording:

 

var idGEfc = charIDToTypeID( "GEfc" );
    var desc272 = new ActionDescriptor();
    var idGEfk = charIDToTypeID( "GEfk" );
    var idGEft = charIDToTypeID( "GEft" );
    var idposterEdges = stringIDToTypeID( "posterEdges" );
    desc272.putEnumerated( idGEfk, idGEft, idposterEdges );
    var idedgeThickness = stringIDToTypeID( "edgeThickness" );
    desc272.putInteger( idedgeThickness, 3 );
    var idedgeIntensity = stringIDToTypeID( "edgeIntensity" );
    desc272.putInteger( idedgeIntensity, 2 );
    var idposterization = stringIDToTypeID( "posterization" );
    desc272.putInteger( idposterization, 1 );
executeAction( idGEfc, desc272, DialogModes.NO );

 

Here is how the raw recording looks using the CleanSL script:

 

GEfc(3, 2, 1);

function GEfc(edgeThickness, edgeIntensity, posterization) {
	var c2t = function (s) {
		return app.charIDToTypeID(s);
	};
	var s2t = function (s) {
		return app.stringIDToTypeID(s);
	};
	var descriptor = new ActionDescriptor();
	descriptor.putEnumerated(c2t("GEfk"), c2t("GEft"), s2t("posterEdges"));
	descriptor.putInteger(s2t("edgeThickness"), edgeThickness);
	descriptor.putInteger(s2t("edgeIntensity"), edgeIntensity);
	descriptor.putInteger(s2t("posterization"), posterization);
	executeAction(c2t("GEfc"), descriptor, DialogModes.NO);
}

 

Here I have manually created a function and function call and manually replaced the hard-coded values with variable names for the parameters. This is without using the CleanSL script:

 

galleryEffects_PosterEdges(3, 2, 1);

function galleryEffects_PosterEdges(thicknessValue, intensityValue, posterizationValue) {
	var idGEfc = charIDToTypeID("GEfc");
	var desc272 = new ActionDescriptor();
	var idGEfk = charIDToTypeID("GEfk");
	var idGEft = charIDToTypeID("GEft");
	var idposterEdges = stringIDToTypeID("posterEdges");
	desc272.putEnumerated(idGEfk, idGEft, idposterEdges);
	var idedgeThickness = stringIDToTypeID("edgeThickness");
	desc272.putInteger(idedgeThickness, thicknessValue); // Replace the integer with a variable
	var idedgeIntensity = stringIDToTypeID("edgeIntensity");
	desc272.putInteger(idedgeIntensity, intensityValue); // Replace the integer with a variable
	var idposterization = stringIDToTypeID("posterization");
	desc272.putInteger(idposterization, posterizationValue); // Replace the integer with a variable
	executeAction(idGEfc, desc272, DialogModes.NO);
}

 

Next, you would then need to work out what the valid range of values are for each parameter from the user interface... Finally, you would then add in the variables to create the random values for each parameter and replace the numerical values with the variable names as I previously did with my initial example.

Votes

Translate

Report

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
New Here ,
Mar 01, 2025 Mar 01, 2025

Copy link to clipboard

Copied

Hey Stephen,

 

Thank you so much for the prompt and thoughtful response. 

 

In regard to specifics, what I'm looking for is the following:

  • The script I'd like would only need to randomise one filter at once. I'd use this one script and run it multiple times within a single Photoshop action if I I needed to randomise multiple filters.
  • Once the script runs a specific filter I would like it to randomise at least all of the parameters that take in integer inputs.

 

With that being said I have two questions:

  1. In order to randomise a filter based on a script, would I be able to use one singular script or would each filter require its own randomisation script? If each requires its own script, do you think it would be possible to have a sort of master script that would allow me to easily change parts of the code of the script based on the filter I'm using or would each separate script have a completely new structure?
  2.  Is it possible to randomise parameters that aren't integers? For example, the Neon Glow filter that has a parameter that takes a color. Is this something that could be randomised as well? Another example is the Rough Pastels filter which has a parameter titled scaling that takes in a percent value ranging from 50% to 200%. Could this type of parameter be randomised?

Votes

Translate

Report

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 ,
Mar 01, 2025 Mar 01, 2025

Copy link to clipboard

Copied

You need a separate function for each separate filter. Each function would have random parameters that may or may not be shared with other filters.

 

All of the functions could be in the one script, with function calls as necessary to run specific randomised filters. Or they could all be separate self contained scripts, each with a unique function and function call.

 

It depends on the parameters as to how one would code the randomised values. Some would be easier than others.

 

Just how many different filters are you looking at randomising? It could take anywhere from a couple of minutes to much longer, per filter to create the randomised parameters, not including testing and bug fixes.

 

This can easily be a black hole for time.

Votes

Translate

Report

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
New Here ,
Mar 01, 2025 Mar 01, 2025

Copy link to clipboard

Copied

Ok that makes sense, I completely understand how it could be a black hole for time. Therefore, I think I'll be ok as long as I understand how to alter the script you write to fit other filter gallery filters that use integers as inputs. I typed some steps below summarizing what I think the necessary changes would be to modify your script for another filter. Were the 5 steps I summarized correct or am I forgetting anything?

Votes

Translate

Report

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 ,
Mar 01, 2025 Mar 01, 2025

Copy link to clipboard

Copied

It's rarely that easy, the names are not always logical or obvious. To self serve, you're going to need to install the following:

 

ScriptingListener plugin from Adobe:

 

https://helpx.adobe.com/au/photoshop/kb/downloadable-plugins-and-content.html

 

Although not strictly necessary, I highly recommend the CleanSL script to refactor and create functions from the basic code recordings:

 

https://community.adobe.com/t5/photoshop-ecosystem-discussions/clean-sl/td-p/9358420

 

https://github.com/rendertom/Clean-SL

Votes

Translate

Report

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 ,
Mar 01, 2025 Mar 01, 2025

Copy link to clipboard

Copied

quote

 Is it possible to randomise parameters that aren't integers? For example, the Neon Glow filter that has a parameter that takes a color. Is this something that could be randomised as well

 

Yes, the Red/Green/Blue values are just three separate integers between 0-255 in value, so easy enough with the code previously provided as a guide.

 

quote

Another example is the Rough Pastels filter which has a parameter titled scaling that takes in a percent value ranging from 50% to 200%. Could this type of parameter be randomised?


By ugonnaa21431338

 

The scaling value is still an integer, so easy enough with the code previously provided as an example.

 

What will be more challenging are parameters using specific names, such as the texture and the light direction parameters.

 

Here's an example of randomising the texture, which is based on an array of four names, rather than integers:

 

var textures = ["texTypeBrick", "texTypeBurlap", "texTypeCanvas", "texTypeSandstone"];
var randomTexture = textures[Math.floor(Math.random() * textures.length)];
alert(randomTexture);
GEfc_roughPastels(6, 4, randomTexture, 111, 20, false);

function GEfc_roughPastels(strokeLength, strokeDetail, theTexture, scaling, relief, invertTexture) {
    var c2t = function (s) {
        return app.charIDToTypeID(s);
    };
    var s2t = function (s) {
        return app.stringIDToTypeID(s);
    };
    var descriptor = new ActionDescriptor();
    descriptor.putEnumerated(c2t("GEfk"), c2t("GEft"), s2t("roughPastels"));
    descriptor.putInteger(s2t("strokeLength"), strokeLength);
    descriptor.putInteger(s2t("strokeDetail"), strokeDetail);
    descriptor.putEnumerated(s2t("textureType"), s2t("textureType"), s2t(theTexture));
    descriptor.putInteger(s2t("scaling"), scaling);
    descriptor.putInteger(s2t("relief"), relief);
    descriptor.putEnumerated(s2t("lightDirection"), s2t("lightDirection"), s2t("lightDirBottomRight"));
    descriptor.putBoolean(s2t("invertTexture"), invertTexture);
    executeAction(c2t("GEfc"), descriptor, DialogModes.NO);
}

 

You can remove or //comment out the alert line, it's just there so that you can see what is going on.

 

A similar approach could be used for the light direction, which has eight parameters.

 

This project will be a labour of love... Good luck!

Votes

Translate

Report

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
New Here ,
Mar 08, 2025 Mar 08, 2025

Copy link to clipboard

Copied

Hello @Stephen Marsh  - thank you for all the help. Since we last spoke I've begun creating a couple of these randomization scripts for my personal use. Some of them are working but for others I'm running into a particular issue where the filter gallery effect isn't taking in the random values/parameters that I'm creating. The following is an example:

 

#target photoshop
app.bringToFront();

if (app.documents.length > 0) {
    var doc = app.activeDocument;

    // Generate random values for the Neon Glow filter parameters
    var glowSize = Math.floor(Math.random() * 49) - 24; // Range: -24 to 24
    var glowBrightness = Math.floor(Math.random() * 51); // Range: 0-50

    // Random RGB color values (each from 0 to 255, as integers)
    var glowColorRed = Math.floor(Math.random() * 256);
    var glowColorGreen = Math.floor(Math.random() * 256);
    var glowColorBlue = Math.floor(Math.random() * 256);

    // DEBUG: Show random values before applying
    alert("Randomized Values:\nGlow Size: " + glowSize + "\nGlow Brightness: " + glowBrightness +
          "\nGlow Color (RGB): " + glowColorRed + ", " + glowColorGreen + ", " + glowColorBlue);

    // Apply the Neon Glow filter with randomized parameters
    applyNeonGlowFilter(glowSize, glowBrightness, glowColorRed, glowColorGreen, glowColorBlue);
} else {
    alert("No open document found.");
}

// Function to apply the Neon Glow filter using the GEfc internal function
function applyNeonGlowFilter(size, brightness, red, green, blue) {
    var c2t = function (s) { return app.charIDToTypeID(s); };
    var s2t = function (s) { return app.stringIDToTypeID(s); };

    var descriptor = new ActionDescriptor();
    descriptor.putEnumerated(c2t("GEfk"), c2t("GEft"), s2t("neonGlow")); // Set filter type to Neon Glow
    descriptor.putInteger(s2t("Sz  "), size); // Randomized Glow Size
    descriptor.putInteger(s2t("Brgh"), brightness); // Randomized Glow Brightness

    // Set Glow Color using RGB values as integers
    var colorDescriptor = new ActionDescriptor();
    colorDescriptor.putInteger(s2t("Rd  "), red);
    colorDescriptor.putInteger(s2t("Grn "), green);
    colorDescriptor.putInteger(s2t("Bl  "), blue);
    
    descriptor.putObject(s2t("Clr "), s2t("RGBC"), colorDescriptor);

    executeAction(c2t("GEfc"), descriptor, DialogModes.NO);
}

 

In the above I created a script to run the neon glow filter and randomize the parameters. I have been able to verify that the random number generator is working correctly but for some reason whenever I use the script Photoshop succesfully applies the filter but it always applies it with the default settings of the filter instead of the random values I generate. I have tried troubleshooting using ChatGPT and other software but nothing is working. Do you know why Photoshop keeps using default values instead of the parameters that I am trying to pass into it? 

Votes

Translate

Report

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 ,
Mar 08, 2025 Mar 08, 2025

Copy link to clipboard

Copied

@ugonnaa21431338 

 

You have done well so far!

 

I think that the issue is in these 5 lines in your function:

 

    descriptor.putInteger(s2t("Sz  "), size); // Randomized Glow Size
    descriptor.putInteger(s2t("Brgh"), brightness); // Randomized Glow Brightness
    var colorDescriptor = new ActionDescriptor();
    colorDescriptor.putInteger(s2t("Rd  "), red);
    colorDescriptor.putInteger(s2t("Grn "), green);
    colorDescriptor.putInteger(s2t("Bl  "), blue);

 

Which should be:

 

    descriptor.putInteger(s2t("size"), size); // Randomized Glow Size
    descriptor.putInteger(s2t("brightness"), brightness); // Randomized Glow Brightness
    colorDescriptor.putInteger(s2t("red"), red);
    colorDescriptor.putInteger(s2t("grain"), green);
    colorDescriptor.putInteger(s2t("blue"), blue);

 

The issue is that you haven't converted the charID's to the expected stringID's. I created a couple of scripts to convert between these here (don't input the quote marks):

 

https://community.adobe.com/t5/photoshop-ecosystem-discussions/action-manager-scripting/td-p/1116032...

Votes

Translate

Report

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
New Here ,
Mar 08, 2025 Mar 08, 2025

Copy link to clipboard

Copied

@Stephen Marsh Thank you so much! I replaced those 5 lines and it has fixed part of the problem. The Glow Size and Glow Brightness parameters are now being correctly randomized. Unfortunately, the color/RGB values still aren't. Do you know what could be causing this? Is it a CharID to StringID issue or something else? 

Votes

Translate

Report

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 ,
Mar 08, 2025 Mar 08, 2025

Copy link to clipboard

Copied

LATEST
quote

Stephen Marsh Thank you so much! I replaced those 5 lines and it has fixed part of the problem. The Glow Size and Glow Brightness parameters are now being correctly randomized. Unfortunately, the color/RGB values still aren't. Do you know what could be causing this? Is it a CharID to StringID issue or something else? 


By ugonnaa21431338

 

Here is my code:

 

 

var neonGlowRandomSize = Math.floor(Math.random() * 49) - 24; // Range: -24 to 24;
var neonGlowRandomBrightness = Math.floor(Math.random() * 51); // Range: 0-50;
var neonGlowRandomRed = Math.floor(Math.random() * 256);
var neonGlowRandomGreen = Math.floor(Math.random() * 256);
var neonGlowRandomBlue = Math.floor(Math.random() * 256);

applyNeonGlowFilter(neonGlowRandomSize, neonGlowRandomBrightness, neonGlowRandomRed, neonGlowRandomGreen, neonGlowRandomBlue);

function applyNeonGlowFilter(size, brightness, red, green, blue) {
    var c2t = function (s) {
        return app.charIDToTypeID(s);
    };
    var s2t = function (s) {
        return app.stringIDToTypeID(s);
    };
    var descriptor = new ActionDescriptor();
    var descriptor2 = new ActionDescriptor();
    descriptor.putEnumerated(c2t("GEfk"), c2t("GEft"), s2t("neonGlow"));
    descriptor.putInteger(s2t("size"), size);
    descriptor.putInteger(s2t("brightness"), brightness);
    descriptor2.putDouble(s2t("red"), red);
    descriptor2.putDouble(s2t("grain"), green);
    descriptor2.putDouble(s2t("blue"), blue);
    descriptor.putObject(s2t("color"), s2t("RGBColor"), descriptor2);
    executeAction(c2t("GEfc"), descriptor, DialogModes.NO);
}

 

Edit: Sorry, I forgot to tell you to update from:

 

    descriptor.putObject(s2t("Clr "), s2t("RGBC"), colorDescriptor);

 

to:

 

    descriptor.putObject(s2t("color"), s2t("RGBC"), colorDescriptor);

 

Votes

Translate

Report

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