Skip to main content
keseyb15419631
Inspiring
September 16, 2020
Answered

[Paid request] Find installed pattern names with script?

  • September 16, 2020
  • 1 reply
  • 4487 views

My app has already shipped and i'm encountering an issue, so I am happy to pay cash today for this help via cashapp/paypal so I can get this running again.

 

 

I'm looking for a way to fetch the names of the users installed patterns. For example, "Trees", "Grass", "Water". I want my extension to automatically install a pattern pack, however what happens is that it reinstalls the same patterns every time it runs. I would like to check if the pattern pack name matches any of the users installed pattersn, and if not, install them.

 

I would also be okay with an alternative method of installation that doesn't require that, but gets the same job done.

 

 

This topic has been closed for replies.
Correct answer r-bin
Such an organization of patterns appeared not so long ago.
What can be done.
This script receives a structure as an array of objects.
The array element contains the path property - an array of strings. Also, if the element is a pattern, it contains the pattern property - the name of the pattern.
 
var r = new ActionReference();    
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("presetManager"));  
r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));

var list = executeActionGet(r).getList(stringIDToTypeID("presetManager")).getObjectValue(4).getList(stringIDToTypeID("name"));        

var patterns = new Array();    

for (var i = 0; i < list.count; i++) patterns.push(list.getString(i));    

var file = new File(Folder.temp.fsName + "/" + "TMP");

file.remove();

var d = new ActionDescriptor();
d.putPath(stringIDToTypeID("null"), file);
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("pattern"));
r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
d.putReference(stringIDToTypeID("to"), r);
executeAction(stringIDToTypeID("set"), d, DialogModes.NO);

patterns.reverse();


file.open("r");
file.encoding = "BINARY";

var s = file.read();

file.remove();

var n = s.indexOf("8BIMphry");

if (n > 0)
    {
    s = s.substr(n+12);

    var d = new ActionDescriptor();
    d.fromStream(s);

    var list = d.getList(stringIDToTypeID("hierarchy"));

    var hierarchy = new Array();

    var grp = new Array();

    for (var i = 0; i < list.count; i++)
        {
        // switch (list.getClass(i)) // not working in ps2021
        switch (list.getObjectType(i)) // edited 1-aug-2021 by r-bin
            {
            case stringIDToTypeID("group"):
                var nm = list.getObjectValue(i).getString(stringIDToTypeID("name"));
                grp.push(nm);

                hierarchy.push({path:[]});

                for (var x = 0; x < grp.length; x++) hierarchy[hierarchy.length-1].path.push(grp[x]);

                break;

            case stringIDToTypeID("groupEnd"):
                grp.pop();
                break;
                

            case stringIDToTypeID("preset"):
                hierarchy.push({path:[]});

                for (var x = 0; x < grp.length; x++) hierarchy[hierarchy.length-1].path.push(grp[x]);

                hierarchy[hierarchy.length-1].pattern = patterns.pop();
                break;
            }
        }

    alert(hierarchy.toSource())        
    }        

1 reply

Legend
September 16, 2020

You can take this script as a basis

var r = new ActionReference();    
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("presetManager"));  
r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));

var list = executeActionGet(r).getList(stringIDToTypeID("presetManager")).getObjectValue(4).getList(stringIDToTypeID("name"));        

var patterns = new Array();    

for (var i = 0; i < list.count; i++) patterns.push(list.getString(i));    

alert(patterns);

keseyb15419631
Inspiring
September 16, 2020

Thank you, where should I send a check?! 

 

I'm serious thank you a ton. One question, this seems to deliver the individual texture names instead of the folder/group name. Is that possible to retrieve?

r-binCorrect answer
Legend
September 16, 2020
Such an organization of patterns appeared not so long ago.
What can be done.
This script receives a structure as an array of objects.
The array element contains the path property - an array of strings. Also, if the element is a pattern, it contains the pattern property - the name of the pattern.
 
var r = new ActionReference();    
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("presetManager"));  
r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));

var list = executeActionGet(r).getList(stringIDToTypeID("presetManager")).getObjectValue(4).getList(stringIDToTypeID("name"));        

var patterns = new Array();    

for (var i = 0; i < list.count; i++) patterns.push(list.getString(i));    

var file = new File(Folder.temp.fsName + "/" + "TMP");

file.remove();

var d = new ActionDescriptor();
d.putPath(stringIDToTypeID("null"), file);
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("pattern"));
r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
d.putReference(stringIDToTypeID("to"), r);
executeAction(stringIDToTypeID("set"), d, DialogModes.NO);

patterns.reverse();


file.open("r");
file.encoding = "BINARY";

var s = file.read();

file.remove();

var n = s.indexOf("8BIMphry");

if (n > 0)
    {
    s = s.substr(n+12);

    var d = new ActionDescriptor();
    d.fromStream(s);

    var list = d.getList(stringIDToTypeID("hierarchy"));

    var hierarchy = new Array();

    var grp = new Array();

    for (var i = 0; i < list.count; i++)
        {
        // switch (list.getClass(i)) // not working in ps2021
        switch (list.getObjectType(i)) // edited 1-aug-2021 by r-bin
            {
            case stringIDToTypeID("group"):
                var nm = list.getObjectValue(i).getString(stringIDToTypeID("name"));
                grp.push(nm);

                hierarchy.push({path:[]});

                for (var x = 0; x < grp.length; x++) hierarchy[hierarchy.length-1].path.push(grp[x]);

                break;

            case stringIDToTypeID("groupEnd"):
                grp.pop();
                break;
                

            case stringIDToTypeID("preset"):
                hierarchy.push({path:[]});

                for (var x = 0; x < grp.length; x++) hierarchy[hierarchy.length-1].path.push(grp[x]);

                hierarchy[hierarchy.length-1].pattern = patterns.pop();
                break;
            }
        }

    alert(hierarchy.toSource())        
    }