Copy link to clipboard
Copied
Hi All
I've got a script that works exactly how I want it but it's saving as PSD and my files are too big. Does anyone know how to make it save as PSB?
Thanks loads for any assistance!
Will
// select folder, create files with the contents of one of the subfolders each as layers and save them to the folder;
// use it at your own risk;
#target photoshop
// select a folder;
var sourceFolder = Folder.selectDialog("Select folder");
if (sourceFolder) {
// the psd options;
psdOpts = new PhotoshopSaveOptions();
psdOpts.embedColorProfile = true;
psdOpts.alphaChannels = false;
psdOpts.layers = true;
psdOpts.spotColors = true;
// get the contents as one array per folder;
var items = retrieveFiles(sourceFolder, [[]]);
// iterate through;
for (var m = 1; m < items.length; m++) {
var thisArray = items
; var folderName = thisArray[0].parent.name;
// open file;
var theImage = app.open(File(thisArray[0]));
for (var n = 1; n < thisArray.length; n++) {
// place rest of array;
var theLayer = placeScaleFile(thisArray
, 0, 0, 100); };
// save the stacked file;
theImage.saveAs(new File(sourceFolder+"/"+folderName+".psd"),psdOpts,false);
// close;
theImage.close(SaveOptions.DONOTSAVECHANGES);
};
};
////// get from subfolders //////
function retrieveFiles (theFolder, theFiles) {
if (!theFiles) {var theFiles = [[]]};
var theContent = theFolder.getFiles();
for (var n = 0; n < theContent.length; n++) {
var theObject = theContent
; if (theObject.constructor.name == "Folder") {
theFiles.push(new Array)
retrieveFiles(theObject, theFiles)
};
if (theObject.name.match(new RegExp(/\.(jpe|jpg|jpeg|gif|png|tif|tiff|bmp|psd|dng|pict|eps|raw|rw2|crw|cr2)/i)) != null) {
theFiles[theFiles.length - 1].push(theObject)
}
};
return theFiles
};
////// get psds, tifs and jpgs from files //////
function getFiles (theFile) {
if (theFile.name.match(/\.(eps|ai|jpg|tif|psd|pdf|)$/i)) {
return true
};
};
////// place //////
function placeScaleFile (file, xOffset, yOffset, theScale) {
// =======================================================
var idPlc = charIDToTypeID( "Plc " );
var desc5 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
desc5.putPath( idnull, new File( file ) );
var idFTcs = charIDToTypeID( "FTcs" );
var idQCSt = charIDToTypeID( "QCSt" );
var idQcsa = charIDToTypeID( "Qcsa" );
desc5.putEnumerated( idFTcs, idQCSt, idQcsa );
var idOfst = charIDToTypeID( "Ofst" );
var desc6 = new ActionDescriptor();
var idHrzn = charIDToTypeID( "Hrzn" );
var idPxl = charIDToTypeID( "#Pxl" );
desc6.putUnitDouble( idHrzn, idPxl, xOffset );
var idVrtc = charIDToTypeID( "Vrtc" );
var idPxl = charIDToTypeID( "#Pxl" );
desc6.putUnitDouble( idVrtc, idPxl, yOffset );
var idOfst = charIDToTypeID( "Ofst" );
desc5.putObject( idOfst, idOfst, desc6 );
var idWdth = charIDToTypeID( "Wdth" );
var idPrc = charIDToTypeID( "#Prc" );
desc5.putUnitDouble( idWdth, idPrc, theScale );
var idHght = charIDToTypeID( "Hght" );
var idPrc = charIDToTypeID( "#Prc" );
desc5.putUnitDouble( idHght, idPrc, theScale );
var idLnkd = charIDToTypeID( "Lnkd" );
desc5.putBoolean( idLnkd, true );
executeAction( idPlc, desc5, DialogModes.NO );
return app.activeDocument.activeLayer;
};
Copy link to clipboard
Copied
Can you not just record that part with scriptlistener plug-in…?
Copy link to clipboard
Copied
In all honesty I had no idea such a thing existed.! I'll do a search and have a go. Thanks Mark
Copy link to clipboard
Copied
Your placeScaleFile function is a scriptlistener recording… I guess someone else provided this snippet then…
function saveAsPSB( filePath ) {
function cTID(s) { return app.charIDToTypeID(s); };
//function sTID(s) { return app.stringIDToTypeID(s); };
var desc7 = new ActionDescriptor();
var desc8 = new ActionDescriptor();
desc7.putObject( cTID('As '), cTID('Pht8'), desc8 );
desc7.putPath( cTID('In '), new File( filePath ) );
desc7.putBoolean( cTID('LwCs'), true );
executeAction( cTID('save'), desc7, DialogModes.NO );
};
Copy link to clipboard
Copied
Hi Will,
Did you find a solution to this?
I managed to save it as a tiff, but no luck saving to PSB.