Skip to main content
ugonnaa21431338
Participating Frequently
March 1, 2025
Question

Photoshop Script for randomizing paramters within the Filter Gallery

  • March 1, 2025
  • 1 reply
  • 651 views

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 🙂 

1 reply

Stephen Marsh
Community Expert
Community Expert
March 1, 2025

@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?

Stephen Marsh
Community Expert
Community Expert
March 2, 2025

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.

 

 

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.

ugonnaa21431338
Participating Frequently
March 2, 2025

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!!!