Copy link to clipboard
Copied
If anyone is interested, I have written a script that will save open documents as PSB files to a folder location of your choosing. It runs as a batch script meaning it will run on all open PS documents. It also names the file based on the name of the active layer selected when you run the script. Handy for those who Load Files as Photoshop Layers out of Bridge and then want to use a layer name as the main file name. I use this regularly in my pipeline and it's fantastic.
CJI_SAVE AS PSB_LYR NAME.jsx
// Adobe Photoshop script to save all open documents as .PSB files using the selected layer name
try {
// Prompt the user to select a destination folder
var destinationFolder = Folder.selectDialog("Select a folder to save .PSB files");
// Check if the user canceled the dialog
if (destinationFolder == null) {
throw new Error("No folder selected. Script canceled.");
}
// Function to get the name of the selected layer
function getSelectedLayerName() {
var activeLayer = app.activeDocument.activeLayer;
return activeLayer.name.replace(/[^a-zA-Z0-9-_]/g, "_"); // Clean the layer name to be file-system friendly
}
// Function to save the document as .PSB using Action Descriptor
function savePSB(saveFile) {
var desc1 = new ActionDescriptor();
var desc2 = new ActionDescriptor();
desc2.putBoolean(stringIDToTypeID('maximizeCompatibility'), true);
desc1.putObject(charIDToTypeID('As '), charIDToTypeID('Pht8'), desc2);
desc1.putPath(charIDToTypeID('In '), new File(saveFile));
desc1.putBoolean(charIDToTypeID('LwCs'), true);
executeAction(charIDToTypeID('save'), desc1, DialogModes.NO);
}
// Function to save the document as a .PSB file using the selected layer name
function saveAsPSB(doc, folder) {
var layerName = getSelectedLayerName();
var savePath = folder + "/" + layerName + ".psb";
var filePath = new File(savePath);
// Convert to PSB format if not already set
if (!doc.bigDocument) {
doc.bigDocument = true;
}
// Use the Action Descriptor method to save as .PSB
savePSB(filePath);
}
// Get the list of open documents
var openDocs = app.documents;
// Check if there are any open documents
if (openDocs.length === 0) {
alert("No open documents found.");
} else {
// Save each open document as a .PSB file with the selected layer name
for (var i = 0; i < openDocs.length; i++) {
var doc = openDocs[i];
app.activeDocument = doc; // Make the document active
saveAsPSB(doc, destinationFolder);
}
alert("All open documents have been saved as .PSB files using the selected layer name.");
}
} catch (e) {
alert("Error: " + e.message);
}
Copy link to clipboard
Copied
Hi Carson Jones,
and thanks for sharing! I do really admire people who take the time ad aggravation to create these scripts. Good work!