Copy link to clipboard
Copied
Hello
I need script that can copy all layers names to some metadata field in the same picture, like keywords or similar...In this way I can sort files in bridge which have layers to some subfolder thanks
Copy link to clipboard
Copied
Code for collecting the layernames is available, this version also collect the layerIDs, though.
// 2015, use it at your own risk;
#target "photoshop-70.032"
if (app.documents.length > 0) {
app.activeDocument.suspendHistory("replace", "main ()");
};
////////////////////////////////////
function main () {
// the file;
var myDocument = app.activeDocument;
// get number of layers;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var applicationDesc = executeActionGet(ref);
var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));
// process the layers;
var theLayers = new Array;
for (var m = 0; m <= theNumber; m++) {
try {
var ref = new ActionReference();
ref.putIndex( charIDToTypeID( "Lyr " ), m);
var layerDesc = executeActionGet(ref);
var layerSet = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("layerSection")));
var isBackground = layerDesc.getBoolean(stringIDToTypeID("background"));
// if not layer group collect values;
if (layerSet != "layerSectionEnd"/* && layerSet != "layerSectionStart" && isBackground != true*/) {
var theName = layerDesc.getString(stringIDToTypeID('name'));
var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));
theLayers.push([theName, theID])
};
}
catch (e) {};
};
alert (theLayers.join("\n"));
};
But I wonder if Bridge-Scripting may not offer an easier solution for identifying layers files.
Copy link to clipboard
Copied
Tnx for script but dont know how to put script output into keywords?
I ask in bridge scripting but no success. Bridge script will be great.
tif2jpeg conversion. How to find tif or photoshop eps files which have layers or transparencies???
Script to copy all layers names into keywords metadata...sorting files which have layers
Really strange that no one have this needs. I surf all over internet for days and nothing.
Spotlight in mac have some option but dont know how to use it and if it only for psd, i need for tiff:
Tips & Techniques: Spotlight sees PSD layer names, Adobe Bridge doesn't
Copy link to clipboard
Copied
#target "photoshop-70.032"
var doc = activeDocument;
doc.info.keywords = ["aaa", "bbb", "ccc"];// insert your actual content in the array
Copy link to clipboard
Copied
thanks for this but i dont know how to do this. My coworkers need to convert tif to jpegs but not files which have layers or transparency. So i need way to separate flattened tiff from one which have layers or transparency.
In this way I can make droplet.
Maybe is fast way to copy all layers name to clipboard and paste it into description/keywords field?
Copy link to clipboard
Copied
Quite frankly it is peculiar for you to mention what the actual task is only now.
And your approach seems unnecessarily complicated.
Copy link to clipboard
Copied
I assume a simple check for the number of Layers and if only one Layer exists whether it is the Background Layer may suffice.
Copy link to clipboard
Copied
Yes. But because i cant write script i need finished javascript for pc, shop cs6. Simply, tif to jpeg but no one which have layers. In this way i will make droplet.
Copy link to clipboard
Copied
And to skeep images which have transparency as weel.
Copy link to clipboard
Copied
This determines if the active document has more than the background layer.
// 2015, use it at your own risk;
#target photoshop
if (app.documents.length > 0) {
var myDoc = app.activeDocument;
if (myDoc.layers.length == 1 && myDoc.layers[0].isBackgroundLayer == true) {
alert ("image has only background layer")
} else {
alert ("image has more than just a background layer")
}
};
Instead of the alerts you can insert whatever Photoshop operations you want.
Examples for saving tif and jpg are available on the Forum.
Copy link to clipboard
Copied
I will save action. First step is to call this script and if here is layer close image?, open next and if here is no layer image stay open and save as jpeg.
Is this ok?
Copy link to clipboard
Copied
// 2015, use it at your own risk;
#target photoshop
if (app.documents.length > 0) {
var myDoc = app.activeDocument;
if (myDoc.layers.length == 1 && myDoc.layers[0].isBackgroundLayer == true) {
} else {
activeDocument.close()
}
};
Script close image if here is layers, good...but how to make it if here is NO layer to automatically save as jpeg with some setting to same folder as original? want to make droplet.
Copy link to clipboard
Copied
There are numerous examples on this site, here are but a few.
Copy link to clipboard
Copied
some progress
this work, bypass images with layers and save jpg from files without layers to source folder.
but how to kill alert window (the command close is currently unavailable), when run script from action panel? This is because script close image before last step "close" in action panel.
// 2015, use it at your own risk;
#target photoshop
if (app.documents.length > 0) {
var myDoc = app.activeDocument;
if (myDoc.layers.length == 1 && myDoc.layers[0].isBackgroundLayer == true) {
var doc = app.activeDocument;
var Path = doc.path;
var Name = doc.name.replace(/\.[^\.]+$/, '');
var Suffix = "-Photoshop";
var saveFile = File(Path + "/" + Name + Suffix + ".jpg");
SaveJPEG(saveFile, 10);
function SaveJPEG(saveFile, jpegQuality){
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = false;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = jpegQuality; // 10
activeDocument.saveAs(saveFile, jpgSaveOptions, true,Extension.LOWERCASE);
}
} else {
activeDocument.close()
}
};
Copy link to clipboard
Copied
After many many copy/paste trial/error I have finished script thanks to post #9. CS6 on Windows. Someone can clean code. Error log go to Windows/temp for easy clean.
Script convert layered images to pdf format which I think is better than psd and into source subfolder PDFs. PDF parameters is in the script.
Script convert non-layered images to jpg format and into source subfolder JPGs. JPG parameters is in the script.
1. Copy script "Layered PSD-TIF to layered PDF_Non-layered to JPG.jsx" to C:\Program Files\Adobe\Adobe Photoshop CS6 (64 Bit)\Presets\Scripts
2. Copy droplet "Layered PSD-TIF to layered PDF_Non-layered to JPG.exe" somewhere on pc.
3. Load actions set1 into action panel
4. Drop images onto droplet and wait.
download
// 2015, use it at your own risk;
#target photoshop
if (app.documents.length > 0) {
var myDoc = app.activeDocument;
if (myDoc.layers.length == 1 && myDoc.layers[0].isBackgroundLayer == true) {
// Defines the active document that is opened
var docRef = app.activeDocument;
var imgName= docRef.name;
imgName = imgName.substr(0, imgName.length -4);
// Get name of Folder Path
var docFolder = docRef.fullName.parent;
var folderPath = docFolder.fsName;
// Create a sub-folder called PDFs in the working folder
var newPathFolder = new Folder( folderPath + "//JPGs/");
newPathFolder.create();
// Save Options for JPGs
var saveFile = new File( folderPath + "//JPGs/" + imgName + ".jpg");
SaveJPEG(saveFile, 10);
function SaveJPEG(saveFile, jpegQuality){
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = false;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = jpegQuality; // 10
activeDocument.saveAs(saveFile, jpgSaveOptions, true,Extension.LOWERCASE);
}
} else {
// Defines the active document that is opened
var docRef = app.activeDocument;
var imgName= docRef.name;
imgName = imgName.substr(0, imgName.length -4);
// Get name of Folder Path
var docFolder = docRef.fullName.parent;
var folderPath = docFolder.fsName;
// Create a sub-folder called PDFs in the working folder
var newPathFolder = new Folder( folderPath + "//PDFs/");
newPathFolder.create();
// Save Options for PDFs
pdfFile = new File( folderPath + "//PDFs/" + imgName + "_photoshop.pdf")
pdfSaveOptions = new PDFSaveOptions()
pdfSaveOptions.layers = true;
pdfSaveOptions.embedColorProfile = false;
pdfSaveOptions.PDFStandard = PDFStandard.NONE;
pdfSaveOptions.PDFCompatibility = PDFCompatibility.PDF17;
pdfSaveOptions.preserveEditing=true;
pdfSaveOptions.embedThumbnail=true;
pdfSaveOptions.optimizeForWeb = true;
pdfSaveOptions.downSample = PDFResample.NONE;
pdfSaveOptions.encoding = PDFEncoding.PDFZIP;
pdfSaveOptions.colorConversion = false;
pdfSaveOptions.profileInclusionPolicy = false;
pdfSaveOptions.alphaChannels = true;
// set to NONE to allow PDF Security Options. Permission is for Printing only. A common password
// needs to be added as soon as the file is saved without typing it in all the time
docRef.saveAs(pdfFile, pdfSaveOptions, true, Extension.LOWERCASE);
docRef.close(SaveOptions.DONOTSAVECHANGES);
}
};