Copy link to clipboard
Copied
So, I'm new to scripting in photoshop, and want to create a script that does the folowing:
- Show layer 'Slate Grey'
- Export as 'FileName-Edited-SG.jpg' - (location: source folder)
- Hide layer 'Slate Grey'
- Show layer 'White Wash'
- Export as 'FileName-Edited-WW.jpg' - (location: source folder)
- Hide layer 'White Wash'
- Save as FileName-Edited.psd
- Close
How do I do this? Someone please advise if it's possible!
Thanks in advance,
Sam
Hi Sam, let me know how this goes:
/*
Photoshop Scripting Help Please!
https://community.adobe.com/t5/photoshop/photoshop-scripting-help-please/td-p/11890873
Stephen Marsh - 2021
*/
if (app.documents.length > 0) {
var baseName = app.activeDocument.name.replace(/\.[^\.]+$/, '');
var docPath = app.activeDocument.path;
selectSet(false, "Slate Grey");
activeLayerVisibility("Shw "); // "Shw " | "Hd "
// var SGname = "-Edited-SG";
// Regex create initials from layer set
...
Copy link to clipboard
Copied
Can you post a cropped screenshot of the layers panel?
I'm presuming that the layers could be named anything? Are they always going to be only two separate words? Or do all of the files always only have two layers of the same name but different file names?
Is it simply a case of adding -WW or -SG (from the layer words) etc to the end of the current filename?
Is the original document named FileName-Edited.psd or is it FileName.psd and you want to add -Edited?
The workflow is known to you and obvious, however, it is not obvious to me.
Note: Export As and Quick Export are not accessible to scripting, which leaves save for web or save as.
Copy link to clipboard
Copied
The first screenshot shows the layers panel for 'Filename-Edited-SG', 2nd shows the layers for 'Filename-Edited-WW'
I need a script that saves these two variations.with 'Edited-WW' or 'Edited-SG' on the end of the original file name.
Doesn't have to be Export As, I just thought it would be using that as it lets you add a suffix.
Need any more info let me know!
Copy link to clipboard
Copied
Ah, a set within a set... This is proving tougher than I first thought!
Copy link to clipboard
Copied
Hi Sam,
Original_File_Name.psd
Original_File_Name-Edited-SG.jpg
Original_File_Name-Edited-WW.jpg
Original_File_Name-Edited.psd
Is there really a need to save another PSD copy at the end of the workflow with a different name?
Why can't the script simply close down the original PSD without saving any changes after the two JPG files are saved? There have been no edits made to the original file, apart from turning a couple of layer set's visibility on and off.
Copy link to clipboard
Copied
Hi Stephen,
Yes that would be fine, it was just so we could see what's been edited but as there's no .psd to start with it's clear anyway. If it makes it easier, just a save (with original_file_name.psd) and close would be fine.
Thanks
Copy link to clipboard
Copied
Easier still, just a close without saving would be fine too if it makes it easier as you say the changes made are minute.
Copy link to clipboard
Copied
It's all good, it is pretty much the same whether saving or not, I was just asking as I am laying out the saving steps in the script and the question came to me.
Copy link to clipboard
Copied
Hi Sam, let me know how this goes:
/*
Photoshop Scripting Help Please!
https://community.adobe.com/t5/photoshop/photoshop-scripting-help-please/td-p/11890873
Stephen Marsh - 2021
*/
if (app.documents.length > 0) {
var baseName = app.activeDocument.name.replace(/\.[^\.]+$/, '');
var docPath = app.activeDocument.path;
selectSet(false, "Slate Grey");
activeLayerVisibility("Shw "); // "Shw " | "Hd "
// var SGname = "-Edited-SG";
// Regex create initials from layer set name
var SGname = app.activeDocument.activeLayer.name.replace(/([a-z]+[a-z]+\b ?)/g, '');
var SG = "-Edited-" + SGname;
var saveFileJPG = new File(docPath + '/' + baseName + SG + '.jpg');
saveJPG(saveFileJPG);
activeLayerVisibility("Hd "); // "Shw " | "Hd "
selectSet(false, "White Wash");
activeLayerVisibility("Shw "); // "Shw " | "Hd "
// var WWname = "-Edited-WW";
// Regex create initials from layer set name
var WWname = app.activeDocument.activeLayer.name.replace(/([a-z]+[a-z]+\b ?)/g, '');
var WW = "-Edited-" + WWname;
var saveFileJPG = new File(docPath + '/' + baseName + WW + '.jpg');
saveJPG(saveFileJPG);
activeLayerVisibility("Hd "); // "Shw " | "Hd "
app.runMenuItem(stringIDToTypeID('selectNoLayers'));
var saveFilePSD = new File(docPath + '/' + baseName + '-Edited' + '.psd');
SavePSD(saveFilePSD);
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
function selectSet(MkVs, setName) {
var c2t = function (s) {
return app.charIDToTypeID(s);
};
var descriptor = new ActionDescriptor();
var list = new ActionList();
var reference = new ActionReference();
reference.putName(c2t("Lyr "), setName);
descriptor.putReference(c2t("null"), reference);
descriptor.putBoolean(c2t("MkVs"), MkVs);
list.putInteger(30);
descriptor.putList(c2t("LyrI"), list);
executeAction(c2t("slct"), descriptor, DialogModes.NO);
}
function activeLayerVisibility(toggle) {
var c2t = function (s) {
return app.charIDToTypeID(s);
};
var descriptor = new ActionDescriptor();
var list = new ActionList();
var reference = new ActionReference();
reference.putEnumerated(c2t("Lyr "), c2t("Ordn"), c2t("Trgt"));
list.putReference(reference);
descriptor.putList(c2t("null"), list);
executeAction(c2t(toggle), descriptor, DialogModes.NO);
}
function SavePSD(saveFilePSD) {
psdSaveOptions = new PhotoshopSaveOptions();
psdSaveOptions.embedColorProfile = true;
psdSaveOptions.alphaChannels = true;
psdSaveOptions.layers = true;
psdSaveOptions.annotations = true;
psdSaveOptions.spotColors = true;
activeDocument.saveAs(saveFilePSD, psdSaveOptions, true, Extension.LOWERCASE);
}
function saveJPG(saveFileJPG) {
var jpgOptions = new JPEGSaveOptions();
jpgOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgOptions.embedColorProfile = true;
jpgOptions.matte = MatteType.NONE;
jpgOptions.quality = 12;
app.activeDocument.saveAs(saveFileJPG, jpgOptions, true, Extension.LOWERCASE);
}
}
else {
alert('A document must be open to use this script!');
}
It is not what I originally planned, however, it should get the job done.
https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html
Copy link to clipboard
Copied
Fantastic, thank you. Really appreciate your efforts!
I'm going to try it now to see if it works.
Sam
Copy link to clipboard
Copied
Legend! All works as intended.
Thanks mate.