• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

script for files contain layer with name, or path with name

Explorer ,
Oct 09, 2022 Oct 09, 2022

Copy link to clipboard

Copied

hi every body, i try to custom a scritp

 

it contain:

 

try{app.doAction("update pdf", "Actions par défaut")}catch(e){}

 

 

update pdf is an action , this action can work only if psd file contain a layer with name "<< doubleclick tochange etiquette"  it s franglish

 

if the file have this layer we can excute action, if not, we do next file

 

 

 

and other question, i my folder , i have many psd file, i want use my script only for psd file with path contain the word "mockup" somewhere

 

how to write that?

 

thanks

TOPICS
Actions and scripting , Windows

Views

401

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Oct 13, 2022 Oct 13, 2022

i do that for resolve....

var topFolder = (Folder.selectDialog("Select the top level folder."))
var fileandfolderArray = scanSubFolders(topFolder,/\.(psd)$/i);

var fileList = fileandfolderArray[0];

for (var i = 0; i < fileList.length; i++) {
var myFile = fileList[i];
   
app.open(myFile);
// check whether layer of a certain name exists in photoshop;

if (app.documents.length > 0) {
var theLayer = checkForLayerName("<< Doubleclick to change etiquette");

if (theLayer == true) {//alert ("layer of
...

Votes

Translate

Translate
Adobe
Community Expert ,
Oct 11, 2022 Oct 11, 2022

Copy link to clipboard

Copied

You need to check for the Layername and use an if-clause (either instead of the try-clause or aditional to it). 

Evaluating all Layers’ names can be done via DOM, but it is usually slower than via AM-code, so that would seem the better approach. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 12, 2022 Oct 12, 2022

Copy link to clipboard

Copied

A basic question is: What is your level structure?
Only layers or perhaps deeply nested layers in groups?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 12, 2022 Oct 12, 2022

Copy link to clipboard

Copied

hi second solution we are trying a script for recursion, but open nothing (designed for indesign)

// extendScript

var defaultFolder = "M:\infographie\Dossier Phykidis\base de donnée produit\pkd\GAMMES\neutre\403 E\etiquette fini - Copie"
var topFolder = Folder(defaultFolder).selectDlg("Select the top level folder.");
if (!topFolder) exit();
var fileandfolderArray = scanSubFolders(topFolder,/\.(indd)$/i);

var fileList = fileandfolderArray[0];
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll


// ici on boucle sur tous les fichiers. C'est normalement que les fichiers etiquette
for (var i = 0; i < fileList.length; i++) {
	OpenAndUpdate(fileList[i])
}
alert("Done updating and saving files!")
  

function scanSubFolders(tFolder, scanMask){
    var subFolders = new Array();
    var allFiles = new Array();
    subFolders[0] = tFolder;
    for (var j = 0; j < subFolders.length; j++){    
        var procFiles = subFolders[j].getFiles();
        for (var i = 0; i< procFiles.length; i++){
            if (procFiles[i] instanceof File ){
                if(scanMask == undefined) allFiles.push(procFiles[i]);
                if (procFiles[i].fullName.search(scanMask) != -1) allFiles.push(procFiles[i]);
        }else if (procFiles[i] instanceof Folder){
            subFolders.push(procFiles[i]);
            scanSubFolders(procFiles[i], scanMask);
         }
      }
   }
   return [allFiles,subFolders];
};

function OpenAndUpdate(doc){
	app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;
	app.open(doc);
	internal_link = app.activeDocument.links;

	for(var j = 0; j < internal_link.length; j++){
		// On vérifie que le lien est OK :
		if (internal_link[j].status == LinkStatus.LINK_MISSING){
			var folderPath = (Folder.selectDialog(internal_link[j].filePath))
			var imglist = Folder(folderPath).getFiles(internal_link[j].name);
			if (imglist.length == 1){
				internal_link[j].relink(imglist[0]);
			}
		}

		// Si le lien est ok. On l'ouvre pour vérifier ses propres lien. La recursivité a lieu ici:
		if (internal_link[i].linkType == 'indd') { // Je ne veux ouvrir que les fichier indd
			OpenAndUpdate(internal_link[i].File) // pas sur. peut etre Filepath à la place de File. cf la doc: https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Link.html
		}
	}
	app.activeDocument.links.everyItem().update();
	app.activeDocument.save();
	app.activeDocument.close();
   return 0; // fin de la fonction. Elle ne renvoie rien normalement
};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 12, 2022 Oct 12, 2022

Copy link to clipboard

Copied

What kind of files do you want open? Indd?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 12, 2022 Oct 12, 2022

Copy link to clipboard

Copied

i have 2 project one for psd, one for indd... actually i work on recursion script for update all link

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 13, 2022 Oct 13, 2022

Copy link to clipboard

Copied

 

// check whether layer of a certain name exists in photoshop;
// 2022, use it at your own risk;
if (app.documents.length > 0) {
var theLayer = checkForLayerName("<< doubleclick tochange etiquette");
if (theLayer == true) {alert ("layer of the name exists")}
};
////// collect layers //////
function checkForLayerName (theString) {
// get number of layers;
var ref = new ActionReference();
ref.putProperty(stringIDToTypeID('property'), stringIDToTypeID('numberOfLayers'));
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 group collect values;
if (layerSet != "layerSectionEnd" /*&& layerSet != "layerSectionStart" && isBackground != true*/) {
var theName = layerDesc.getString(stringIDToTypeID('name'));
if (theName == theString) {return true};
var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));
var theIndex = layerDesc.getInteger(stringIDToTypeID('itemIndex'));
theLayers.push([theName, theIndex, theID])
};
}
catch (e) {};
};
return false
};

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 13, 2022 Oct 13, 2022

Copy link to clipboard

Copied

can you just explain me in few word, what action is done? i try to read for understand but i m not familiary

 

it will open all psd file, if there is layer "douclick....." it will do action "update pdf", if not = no action

 

because i not see the action

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 13, 2022 Oct 13, 2022

Copy link to clipboard

Copied

As it is the Script just checks for the presence of a Layer with the name »<< doubleclick tochange etiquette« and gives an alert if it does. 

You can insert whatever you need in the if-clause 

if (theLayer == true) {alert ("layer of the name exists")}

instead of the alert. 

 

Edit: 

if (theLayer == true) {app.doAction("update pdf", "Actions par défaut")};

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 13, 2022 Oct 13, 2022

Copy link to clipboard

Copied

perfect, i have understand i test now

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 13, 2022 Oct 13, 2022

Copy link to clipboard

Copied

i try to assemblate your script, and an other script

var topFolder = (Folder.selectDialog("Select the top level folder."))
var fileandfolderArray = scanSubFolders(topFolder,/\.(psd)$/i);

var fileList = fileandfolderArray[0];

for (var i = 0; i < fileList.length; i++) {
var myFile = fileList[i];
   
app.open(myFile);

while (app.documents.length > 0) { 

var doc = app.activeDocument;

var docName = fileList[i].name.replace(/\.[^\.]+$/, '');

var outputFolder = Folder(doc.path);

var newFile = new File(decodeURI(outputFolder) + "/" + docName + ".png");

app.runMenuItem(stringIDToTypeID("placedLayerUpdateAllModified"));

exportOptions = new ExportOptionsSaveForWeb();
exportOptions.format = SaveDocumentType.PNG;
exportOptions.PNG8 = false; // false = PNG-24
exportOptions.transparency = true; // true = transparent
exportOptions.interlaced = false; // true = interlacing on
exportOptions.includeProfile = true; // false = don't embedd ICC profile
doc.exportDocument(newFile, ExportType.SAVEFORWEB, exportOptions);

doc.close(SaveOptions.SAVECHANGES);

  }
}
alert("Done processing files!")

function scanSubFolders(tFolder, scanMask){
    var subFolders = new Array();
    var allFiles = new Array();
    subFolders[0] = tFolder;
    for (var j = 0; j < subFolders.length; j++){    
        var procFiles = subFolders[j].getFiles();
        for (var i = 0; i< procFiles.length; i++){
            if (procFiles[i] instanceof File ){
                if(scanMask == undefined) allFiles.push(procFiles[i]);
                if (procFiles[i].fullName.search(scanMask) != -1) allFiles.push(procFiles[i]);
        }else if (procFiles[i] instanceof Folder){
            subFolders.push(procFiles[i]);
            scanSubFolders(procFiles[i], scanMask);
         }
      }
   }
   return [allFiles,subFolders];
};

 

i supose your script will be insert after line 9?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 13, 2022 Oct 13, 2022

Copy link to clipboard

Copied

var topFolder = (Folder.selectDialog("Select the top level folder."))
var fileandfolderArray = scanSubFolders(topFolder,/\.(psd)$/i);

var fileList = fileandfolderArray[0];

for (var i = 0; i < fileList.length; i++) {
var myFile = fileList[i];
   
app.open(myFile);
// check whether layer of a certain name exists in photoshop;
// 2022, use it at your own risk;
if (app.documents.length > 0) {
var theLayer = checkForLayerName("<< doubleclick tochange etiquette");
if (theLayer == true) {alert ("layer of the name exists");
						app.doAction("update pdf", "Actions par défaut");}
};
////// collect layers //////
function checkForLayerName (theString) {
// get number of layers;
var ref = new ActionReference();
ref.putProperty(stringIDToTypeID('property'), stringIDToTypeID('numberOfLayers'));
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 group collect values;
if (layerSet != "layerSectionEnd" /*&& layerSet != "layerSectionStart" && isBackground != true*/) {
var theName = layerDesc.getString(stringIDToTypeID('name'));
if (theName == theString) {return true};
var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));
var theIndex = layerDesc.getInteger(stringIDToTypeID('itemIndex'));
theLayers.push([theName, theIndex, theID])
};
}
catch (e) {};
};
return false
};

while (app.documents.length > 0) { 

var doc = app.activeDocument;

var docName = fileList[i].name.replace(/\.[^\.]+$/, '');

var outputFolder = Folder(doc.path);

var newFile = new File(decodeURI(outputFolder) + "/" + docName + ".png");

app.runMenuItem(stringIDToTypeID("placedLayerUpdateAllModified"));

exportOptions = new ExportOptionsSaveForWeb();
exportOptions.format = SaveDocumentType.PNG;
exportOptions.PNG8 = false; // false = PNG-24
exportOptions.transparency = true; // true = transparent
exportOptions.interlaced = false; // true = interlacing on
exportOptions.includeProfile = true; // false = don't embedd ICC profile
doc.exportDocument(newFile, ExportType.SAVEFORWEB, exportOptions);

doc.close(SaveOptions.SAVECHANGES);

  }
}
alert("Done processing files!")

function scanSubFolders(tFolder, scanMask){
    var subFolders = new Array();
    var allFiles = new Array();
    subFolders[0] = tFolder;
    for (var j = 0; j < subFolders.length; j++){    
        var procFiles = subFolders[j].getFiles();
        for (var i = 0; i< procFiles.length; i++){
            if (procFiles[i] instanceof File ){
                if(scanMask == undefined) allFiles.push(procFiles[i]);
                if (procFiles[i].fullName.search(scanMask) != -1) allFiles.push(procFiles[i]);
        }else if (procFiles[i] instanceof Folder){
            subFolders.push(procFiles[i]);
            scanSubFolders(procFiles[i], scanMask);
         }
      }
   }
   return [allFiles,subFolders];
};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 13, 2022 Oct 13, 2022

Copy link to clipboard

Copied

i m bloqued with error 1320 at line 41...

 

var topFolder = (Folder.selectDialog("Select the top level folder."))
var fileandfolderArray = scanSubFolders(topFolder,/\.(psd)$/i);

var fileList = fileandfolderArray[0];

for (var i = 0; i < fileList.length; i++) {
var myFile = fileList[i];
   
app.open(myFile);
// check whether layer of a certain name exists in photoshop;
// 2022, use it at your own risk;
if (app.documents.length > 0) {
var theLayer = checkForLayerName("<< Doubleclick to change etiquette");
var doc = app.activeDocument;
if (theLayer == true) {//alert ("layer of the name exists");
						app.doAction("update pdf", "Actions par défaut");
						while (app.documents.length > 0) { 
var docName = fileList[i].name.replace(/\.[^\.]+$/, '');

var outputFolder = Folder(doc.path);

var newFile = new File(decodeURI(outputFolder) + "/" + docName + ".png");

app.runMenuItem(stringIDToTypeID("placedLayerUpdateAllModified"));

exportOptions = new ExportOptionsSaveForWeb();
exportOptions.format = SaveDocumentType.PNG;
exportOptions.PNG8 = false; // false = PNG-24
exportOptions.transparency = true; // true = transparent
exportOptions.interlaced = false; // true = interlacing on
exportOptions.includeProfile = true; // false = don't embedd ICC profile
doc.exportDocument(newFile, ExportType.SAVEFORWEB, exportOptions);

doc.close(SaveOptions.SAVECHANGES);

						}
  
} else {
doc.close(SaveOptions.NO);
		}
}
////// collect layers //////
function checkForLayerName (theString) {
// get number of layers;
var ref = new ActionReference();
ref.putProperty(stringIDToTypeID('property'), stringIDToTypeID('numberOfLayers'));
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 group collect values;
if (layerSet != "layerSectionEnd" /*&& layerSet != "layerSectionStart" && isBackground != true*/) {
var theName = layerDesc.getString(stringIDToTypeID('name'));
if (theName == theString) {return true};
var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));
var theIndex = layerDesc.getInteger(stringIDToTypeID('itemIndex'));
theLayers.push([theName, theIndex, theID])
};
}
catch (e) {};
};
return false
};


}
alert("Done processing files!")

function scanSubFolders(tFolder, scanMask){
    var subFolders = new Array();
    var allFiles = new Array();
    subFolders[0] = tFolder;
    for (var j = 0; j < subFolders.length; j++){    
        var procFiles = subFolders[j].getFiles();
        for (var i = 0; i< procFiles.length; i++){
            if (procFiles[i] instanceof File ){
                if(scanMask == undefined) allFiles.push(procFiles[i]);
                if (procFiles[i].fullName.search(scanMask) != -1) allFiles.push(procFiles[i]);
        }else if (procFiles[i] instanceof Folder){
            subFolders.push(procFiles[i]);
            scanSubFolders(procFiles[i], scanMask);
         }
      }
   }
   return [allFiles,subFolders];
};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 13, 2022 Oct 13, 2022

Copy link to clipboard

Copied

i do that for resolve....

var topFolder = (Folder.selectDialog("Select the top level folder."))
var fileandfolderArray = scanSubFolders(topFolder,/\.(psd)$/i);

var fileList = fileandfolderArray[0];

for (var i = 0; i < fileList.length; i++) {
var myFile = fileList[i];
   
app.open(myFile);
// check whether layer of a certain name exists in photoshop;

if (app.documents.length > 0) {
var theLayer = checkForLayerName("<< Doubleclick to change etiquette");

if (theLayer == true) {//alert ("layer of the name exists");
						app.doAction("update pdf", "Actions par défaut");
						while (app.documents.length > 0) { 
var docName = fileList[i].name.replace(/\.[^\.]+$/, '');
var doc = app.activeDocument;
var outputFolder = Folder(doc.path);

var newFile = new File(decodeURI(outputFolder) + "/" + docName + ".png");

app.runMenuItem(stringIDToTypeID("placedLayerUpdateAllModified"));

exportOptions = new ExportOptionsSaveForWeb();
exportOptions.format = SaveDocumentType.PNG;
exportOptions.PNG8 = false; // false = PNG-24
exportOptions.transparency = true; // true = transparent
exportOptions.interlaced = false; // true = interlacing on
exportOptions.includeProfile = true; // false = don't embedd ICC profile
doc.exportDocument(newFile, ExportType.SAVEFORWEB, exportOptions);

doc.close(SaveOptions.SAVECHANGES);

						}
  
} 
	else {
		app.doAction("close", "Actions par défaut");
		}
}
}
alert("Done processing files!")

function scanSubFolders(tFolder, scanMask){
    var subFolders = new Array();
    var allFiles = new Array();
    subFolders[0] = tFolder;
    for (var j = 0; j < subFolders.length; j++){    
        var procFiles = subFolders[j].getFiles();
        for (var i = 0; i< procFiles.length; i++){
            if (procFiles[i] instanceof File ){
                if(scanMask == undefined) allFiles.push(procFiles[i]);
                if (procFiles[i].fullName.search(scanMask) != -1) allFiles.push(procFiles[i]);
        }else if (procFiles[i] instanceof Folder){
            subFolders.push(procFiles[i]);
            scanSubFolders(procFiles[i], scanMask);
         }
      }
   }
   return [allFiles,subFolders];
};
////// collect layers //////
function checkForLayerName (theString) {
// get number of layers;
var ref = new ActionReference();
ref.putProperty(stringIDToTypeID('property'), stringIDToTypeID('numberOfLayers'));
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 group collect values;
if (layerSet != "layerSectionEnd" /*&& layerSet != "layerSectionStart" && isBackground != true*/) {
var theName = layerDesc.getString(stringIDToTypeID('name'));
if (theName == theString) {return true};
var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));
var theIndex = layerDesc.getInteger(stringIDToTypeID('itemIndex'));
theLayers.push([theName, theIndex, theID])
};
}
catch (e) {};
};
return false
};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 14, 2022 Oct 14, 2022

Copy link to clipboard

Copied

LATEST

how to modify this line :

var topFolder = (Folder.selectDialog("Select the top level folder."))
var fileandfolderArray = scanSubFolders(topFolder,/\.(psd)$/i);

 

for open ony psd (or indd)file with a specific name exemple etiquette fini.indd

 

thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines