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

How to get all Photoshop styles using photoshop scripting?

New Here ,
Dec 18, 2022 Dec 18, 2022

I want to randomly apply styles to my ArtLayers. To do this, I tested the applyStyle function.

 

ezIhfexpand image

It works!)

But to solve my task I need all styles. I can't find it in the documentation (photoshop-javascript-ref-2020).

Can you suggest something?

TOPICS
Actions and scripting , Windows
353
Translate
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
Participant ,
Dec 27, 2022 Dec 27, 2022

A track where you must know the path of your PS presets :

 

var stylesFound = false;
main();
if (!stylesFound) {
	alert("No styles found. You should verify the path to your Photoshop style presets.");
}
function main() {
	var styleFolder = Folder('/c/Program Files (x86)/Adobe/Adobe Photoshop CS5/Presets/Styles');
	// Set all style names in an array
	var styleList = styleFolder.getFiles(/\.(asl|)$/i);
	//styleList = styleFile.substring( 0, docRef.name.indexOf('.') );
	// STOP if not any ASL file found
	stylesFound = true;
	if (styleList.length==0) {
		stylesFound = false;
		return;
	}	
	// Random
	var rnd = Math.floor(Math.random() * styleList.length);
	var styleName = styleList[rnd].name;
	alert(styleName);
}
Translate
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 ,
Jan 07, 2023 Jan 07, 2023

Did @michelr31372089 â€™s post help you in this task? 

Translate
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
Guide ,
Jan 11, 2023 Jan 11, 2023
LATEST

[video]

 

 

activeDocument.suspendHistory('Apply random style', 'main()');

function main() {
    activeDocument.artLayers.add();
    var stylesIndexes = applyStyles();
    activeDocument.activeLayer.remove();
    applyStyles(stylesIndexes[Math.floor(Math.random() * stylesIndexes.length)])
}

function applyStyles(idx) {
    var s2t = stringIDToTypeID,
        err = 0,
        cur = 0,
        stylesIdx = [];
    do {
        (r = new ActionReference()).putIndex(s2t("style"), idx ? idx : cur);
        (d = new ActionDescriptor()).putReference(s2t("null"), r);
        (r1 = new ActionReference()).putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
        d.putReference(s2t("to"), r1);
        try {
            executeAction(s2t("applyStyle"), d, DialogModes.NO);
            if (idx) break;
            err = 0
            stylesIdx.push(cur)
        } catch (e) {
            err++
        }
        cur++
    } while (err < 5)
    return stylesIdx;
}

 

 

 

Translate
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