Copy link to clipboard
Copied
Basically I want to be able to select the group names "Notes" (always layer 0).
I have achieved that when the layer group is named exactly with capital case, but i'd like it to be case insensitive, this is the regex to match that in javascript:
searchText.match(/(??<notes>notes)/im)
Here is my script currently:
main();
function main() {
if (!documents.length) return;
var doc = app.activeDocument;
var notesLayer = doc.layers[0];
// Validate that layer 0 is the "Notes" layer
if(notesLayer.name !== "Notes"){
alert("The Notes layer does not exist.")
return;
}
notesLayer.visible = true;
//var doc_path = doc.path;
//var Name = app.activeDocument.name.replace(/\.[^\.]+$/, '');
//var saveFile = File(doc.path + "/_jpg/" + Name + "-notes.jpg");
//SaveForWeb(saveFile, 80); //change quality here
}
var doc = app.activeDocument;
//var Path = doc.path;
var Name = doc.name.replace(/\.[^\.]+$/, '');
var saveFile = File(doc.path + "/_jpg/" + Name + "-notes.jpg");
//var Suffix = "-specs";
//var saveFile = File(Path + "/_jpg" + Name + Suffix + ".jpg");
SaveJPEG(saveFile, 6);
function SaveJPEG(saveFile, jpegQuality){
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = false;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = jpegQuality;
activeDocument.saveAs(saveFile, jpgSaveOptions, true,Extension.LOWERCASE);
}
//function SaveForWeb(saveFile, jpegQuality) {
// var sfwOptions = new ExportOptionsSaveForWeb();
// sfwOptions.format = SaveDocumentType.JPEG;
// sfwOptions.includeProfile = false;
// sfwOptions.interlaced = 0;
// sfwOptions.optimized = true;
// sfwOptions.quality = jpegQuality; //0-100
// activeDocument.exportDocument(saveFile, ExportType.SAVEFORWEB, sfwOptions);
function revert() {
var idRvrt = charIDToTypeID( "Rvrt" );
executeAction( idRvrt, undefined, DialogModes.NO );
}
revert();
1 Correct answer
Hi heyvirgil​
There are more than one Regex for this.
One way could be
main ();
function main() {
if (!documents.length) return;
var doc = app.activeDocument;
var notesLayer = doc.layers[0];
// Validate that layer 0 is the "Notes" layer
if(notesLayer.name.match(/notes/i) == null) {
alert("The Notes layer does not exist.");
return;
}
alert ("found: " + notesLayer.name.match(/notes/i) + " layer");
// your own stuff
}
Have fun
Explore related tutorials & articles
Copy link to clipboard
Copied
try this:
if (notesLayer.name.toLowerCase() !== "notes")
Copy link to clipboard
Copied
Hi heyvirgil​
There are more than one Regex for this.
One way could be
main ();
function main() {
if (!documents.length) return;
var doc = app.activeDocument;
var notesLayer = doc.layers[0];
// Validate that layer 0 is the "Notes" layer
if(notesLayer.name.match(/notes/i) == null) {
alert("The Notes layer does not exist.");
return;
}
alert ("found: " + notesLayer.name.match(/notes/i) + " layer");
// your own stuff
}
Have fun

