0
How to get all Photoshop styles using photoshop scripting?
New Here
,
/t5/photoshop-ecosystem-discussions/how-to-get-all-photoshop-styles-using-photoshop-scripting/td-p/13430141
Dec 18, 2022
Dec 18, 2022
Copy link to clipboard
Copied
I want to randomly apply styles to my ArtLayers. To do this, I tested the applyStyle function.
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
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Explore related tutorials & articles
Participant
,
/t5/photoshop-ecosystem-discussions/how-to-get-all-photoshop-styles-using-photoshop-scripting/m-p/13447352#M693485
Dec 27, 2022
Dec 27, 2022
Copy link to clipboard
Copied
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);
}
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Expert
,
/t5/photoshop-ecosystem-discussions/how-to-get-all-photoshop-styles-using-photoshop-scripting/m-p/13471920#M696285
Jan 07, 2023
Jan 07, 2023
Copy link to clipboard
Copied
Did @michelr31372089 ’s post help you in this task?
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Guide
,
LATEST
/t5/photoshop-ecosystem-discussions/how-to-get-all-photoshop-styles-using-photoshop-scripting/m-p/13483899#M697943
Jan 11, 2023
Jan 11, 2023
Copy link to clipboard
Copied
[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;
}
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

