I tend to work with patterns and have an action to help with this. But, I tend to save my patterns as a .pat file, with anywhere from 10-200 patterns within each .pat file. I am trying to figure out a way to set up an action to create a new pattern fill layer, save it, and then replace the pattern in the fill layer with the next pattern in the .pat file.

What I've got so far...

I open a new file in the size I want (1000x1000 to 9000x5000 depending on what I need)

Set up the Adjustments for all such patterns in that specific folder

Record a new action

New Fill Layer > Pattern

Select the first pattern in the pattern folder for that specific .pat file

Save the file at highest quality

Stop recording the action

Play action - except it only selects the first pattern in that specific pattern folder.

How would I set this up so that, I dunno, I select the pattern folder I am wanting to work with (or .pat file), and then it will select a fill layer with the first pattern, save it, and when run again, it will select the 2nd, then 3rd, and so on so that I can do a batch to get them all saves individually in all the different sizes I want/need?

EDIT: Here is a script for applying the newest made pattern to a fill layer, though it does nothing but select the newest pattern in a .pat file instead of selecting the 1st, then 2nd, and so on

#target photoshop;

function main() {
    if (!documents.length) return;
    var patt = new File(Folder.temp + "/tempPatterns");
    if (patt.exists) patt.remove();
    var patterns = getPatternsFromFile(patt);
    fillPattern(patterns[patterns.length - 1][0].toString(), patterns[patterns.length - 1][1].toString(), 100);

function savePatterns(file) {
    var desc625 = new ActionDescriptor();
    desc625.putPath(charIDToTypeID('null'), new File(file));
    var ref462 = new ActionReference();
    ref462.putProperty(charIDToTypeID('Prpr'), charIDToTypeID('Ptrn'));
    ref462.putEnumerated(charIDToTypeID('capp'), charIDToTypeID('Ordn'), charIDToTypeID('Trgt'));
    desc625.putReference(charIDToTypeID('T   '), ref462);
    executeAction(charIDToTypeID('setd'), desc625, DialogModes.NO);

function getPatternsFromFile(file) {
    file.encoding = 'BINARY';
    var str = file.read();
    var patterns = [];
    var re = /(\x00\w|\x00\d)(\x00\-|\x00\w|\x00\s|\x00\d)+\x00\x00\$[-a-z\d]+/g;
    var parts = str.match(re);
    for (var i = 0; i < parts.length; i++) {
        var p = parts;
        var sp = p.replace(/\x00/g, '').split('$');
    return patterns;

function fillPattern(name, id, opacity) {
    var desc6 = new ActionDescriptor();
    desc6.putEnumerated(charIDToTypeID('Usng'), charIDToTypeID('FlCn'), charIDToTypeID('Ptrn'));
    var desc7 = new ActionDescriptor();
    desc7.putString(charIDToTypeID('Nm  '), name);
    desc7.putString(charIDToTypeID('Idnt'), id);
    desc6.putObject(charIDToTypeID('Ptrn'), charIDToTypeID('Ptrn'), desc7);
    desc6.putUnitDouble(charIDToTypeID('Opct'), charIDToTypeID('#Prc'), opacity);
    desc6.putEnumerated(charIDToTypeID('Md  '), charIDToTypeID('BlnM'), charIDToTypeID('Nrml'));
    try {
        executeAction(charIDToTypeID('Fl  '), desc6, DialogModes.NO);
    } catch (e) {}
  • Hello and welcome to GDSE! This question is really nice but I got some confusions! I guess you should be able to load each .pat via scripting but I just can't figure if it's possible to assign pattern via index or not. I'll update once I'll figure out more. – Mr.Online May 18 at 5:46
  • I was able to figure out a script to select the newest pattern made, but it doesn't do anything for those .pat files that I've already created - unless I wanted to recreate them I guess. – damann May 18 at 6:13
  • Update : By using scriptlistener plugin. I found out that every pattern have it's unique id and you can assign fill by using specific id, So I guess you should try finding this id of every pattern, I guess your problem can be automated once you find patterns id. – Mr.Online May 18 at 10:52
  • 1
    Thanks, but I think getting the id for each pattern and then setting a script for it, is less autmatic/batchy than i would want. Thanks for looking into it though! – damann May 18 at 18:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.