Scripte

alle Bilder aus Ordner & Unterordner öffnen

var topFolder = new Folder('/Users/rick.maschke/Desktop/Bilder/');
 var fileandfolderAr = scanSubFolders(topFolder,/.(jpg|tif|psd|bmp|gif|png|)$/i);
 var fileList = fileandfolderAr[0];
 for(var a = 0 ;a < fileList.length; a++)
 {
 //alert(fileList[a]);
 var docRef = open(fileList[a]);
 }
 function scanSubFolders(tFolder, mask) { 
     var sFolders = new Array();
     var allFiles = new Array();
     sFolders[0] = tFolder;
     for (var j = 0; j < sFolders.length; j++){         
         var procFiles = sFolders[j].getFiles();
         for (var i=0;i<procFiles.length;i++){ 
             if (procFiles[i] instanceof File ){
                 if(mask==undefined) allFiles.push(procFiles[i]);
                 if (procFiles[i].fullName.search(mask) != -1) allFiles.push(procFiles[i]); 
         }else if (procFiles[i] instanceof Folder){
             sFolders.push(procFiles[i]);
             scanSubFolders(procFiles[i], mask);
          }
       }
    }
    return [allFiles,sFolders];
 };

 

Bildgröße & DPI verändern

app.activeDocument.resizeImage( '200%', '200%', 304, ResampleMethod.PRESERVEDETAILS, 25 )  

 

DPI analysieren/ verändern

// DPI Größe ausgeben
 alert(app.activeDocument.resolution);
 // Möglichkeit nur die DPI eines Dokuments zu verändern
 app.activeDocument.resizeImage(undefined, undefined, 304.8, ResampleMethod.NONE);

 

alle Bilder aus Ordner & Unterordner öffnen

var topFolder = new Folder('/Users/rick.maschke/Desktop/Bilder/');
 var fileandfolderAr = scanSubFolders(topFolder,/.(jpg|tif|psd|bmp|gif|png|)$/i);
 var fileList = fileandfolderAr[0];
 for(var a = 0 ;a < fileList.length; a++)
 {
 //alert(fileList[a]);
 var docRef = open(fileList[a]);
 }
 function scanSubFolders(tFolder, mask) { 
     var sFolders = new Array();
     var allFiles = new Array();
     sFolders[0] = tFolder;
     for (var j = 0; j < sFolders.length; j++){         
         var procFiles = sFolders[j].getFiles();
         for (var i=0;i<procFiles.length;i++){ 
             if (procFiles[i] instanceof File ){
                 if(mask==undefined) allFiles.push(procFiles[i]);
                 if (procFiles[i].fullName.search(mask) != -1) allFiles.push(procFiles[i]); 
         }else if (procFiles[i] instanceof Folder){
             sFolders.push(procFiles[i]);
             scanSubFolders(procFiles[i], mask);
          }
       }
    }
    return [allFiles,sFolders];
 };

 

zeigt dir den Namen aller geöffneten Bilder an

var docs = app.documents;  
 var filearray = ["Diese Bilder sind geöffnet:",];        
 //ACHTUNG: "Diese Bilder sind geöffnet:" ist auch ein Array-Eintrag. 
 for($i=0; $i < docs.length; $i++)
     {
         filearray.push(docs[$i].name)
     }
 alert(filearray.join("\n "));

 

wandelt markierte Ebenen in einzelne Smart-Objekte um

var docRef = app.activeDocument;
 var numberofLayers = docRef.layers.length
 var activeLayer = docRef.activeLayer;
 cTID = function(s) { return app.charIDToTypeID(s); };
 sTID = function(s) { return app.stringIDToTypeID(s); };
 function newGroupFromLayers(doc) {
     var desc = new ActionDescriptor();
     var ref = new ActionReference();
     ref.putClass( sTID('layerSection') );
     desc.putReference( cTID('null'), ref );
     var lref = new ActionReference();
     lref.putEnumerated( cTID('Lyr '), cTID('Ordn'), cTID('Trgt') );
     desc.putReference( cTID('From'), lref);
     executeAction( cTID('Mk  '), desc, DialogModes.NO );
 };
 function undo() {
    executeAction(cTID("undo", undefined, DialogModes.NO));
 };
 function getSelectedLayers(doc) {
   var selLayers = [];
   newGroupFromLayers();
 var group = doc.activeLayer;
   var layers = group.layers;
 for (var i = 0; i < layers.length; i++) {
     selLayers.push(layers[i]);
   }
 undo();
 return selLayers;
 };
 var selectedLayers = getSelectedLayers(app.activeDocument);
 for( i = 0; i < selectedLayers.length; i++) {
     selectedLayers[i].selected = true;
     docRef.activeLayer = selectedLayers[i];
 }
 for(i=0; i < selectedLayers.length; i++) {
 try {
 docRef.activeLayer = selectedLayers[i];
 createSmartObject(app.activeDocument.activeLayer);
 } catch(e) {}
 }
 function createSmartObject(layer)
 {
     var idnewPlacedLayer = stringIDToTypeID( 'newPlacedLayer' );
     executeAction(idnewPlacedLayer, undefined, DialogModes.NO);
 }

 

Prüfen ob Ebene Name existiert

function makeLayerActiveByName(nm) { 
 function cTID(s) { return app.charIDToTypeID(s); };  
   try {  
     var desc5 = new ActionDescriptor();  
     var ref4 = new ActionReference();  
     ref4.putName( cTID('Lyr '),  nm);  
     desc5.putReference( cTID('null'), ref4 );  
     desc5.putBoolean( cTID('MkVs'), false );  
     executeAction( cTID('slct'), desc5, DialogModes.NO );  
     return true;  
 } catch (e) {  
    return false;  
  }   
 };  
 // usage:  
 if(makeLayerActiveByName('EBENEN-NAME') == true) {
     alert("yes gibt es!!!");
 } else {
     alert("nö gibt es nicht!");
 }

 

Datei bereinigen

activeDocument.pathItems.removeAll();
 activeDocument.channels.removeAll();

 

mehrere Pfade umbennen

var anzahlpfade = 200;
 var neuerPfadname = "Freisteller";
 // var anzahlpfade = prompt ("Wie viele Pfade möchtest du ändern (1-200) ?");
 // var neuerPfadname = prompt ("Bitte gebe einen Pfadnamen ein:");
 if (app.activeDocument.pathItems.length > 0) {
     try{
         for( i = 0; i <= (anzahlpfade - 1); ){
         app.activeDocument.pathItems[i].name = "///";                     
         app.activeDocument.pathItems[i].name = neuerPfadname + "_" + (i+1);
         i = i + 1;
         };
     } catch(e){}
 };
 else { }

 

Ebenen nach Namen sortieren

for (var x = 0; x < app.activeDocument.layers.length; x++) {      for (var y = 0; y < app.activeDocument.layers.length - 1 - x; y++) {            var doc1 = app.activeDocument.layers[y].name            var doc2 = app.activeDocument.layers[y + 1].name                       if (doc1.toUpperCase() > doc2.toUpperCase()) {
                                  app.activeDocument.layers[y].move(app.activeDocument.layers[y+1],ElementPlacement.PLACEAFTER)
                       }
         }
 }

 

Speicherort der geöffneten Datei

app.activeDocument.path

 

Maßeinheiten ändern

app.preferences.rulerUnits = Units.PIXELS;

 

Neues Dokument

app.documents.add(100, 200, 72, "Dateiname")

 

Ebene aus Alpha-Kanal

var doc = activeDocument;
 var lyr = doc.activeLayer;
 var cnt = doc.channels.length;
 for(var i = 1 ;i < cnt;i++){
    if(activeDocument.channels[i].kind != ChannelType.MASKEDAREA) {continue}
    doc.selection.load(doc.channels[i]);
    executeAction( charIDToTypeID( "CpTL" ), undefined, DialogModes.NO );
    doc.activeLayer.name = doc.channels[i].name;
    doc.activeLayer = lyr;
 }

 

Metadaten verändern

/* Ersteller */
 activeDocument.info.author = "Rick Maschke";
 /* Berufsbezeichnung */
 activeDocument.info.authorPosition = "text";
 /* Überschrift */
 activeDocument.info.headline = "text";
 /* Beschreibung */
 activeDocument.info.caption = "text";
 /* Ersteller der Beschreibung */
 activeDocument.info.captionWriter = "text";
 /* Ort */
 activeDocument.info.city = "text";
 /* Land */
 activeDocument.info.country = "text";
 /* Urheberrechtlich geschützt */
 activeDocument.info.copyrighted = CopyrightedType.COPYRIGHTEDWORK
 /* Copyright-Vermerk */
 activeDocument.info.copyrightNotice = "Text"
 /* titel-Vermerk */
 activeDocument.info.title = "Text"
 var aut = activeDocument.info.author;
 var head = activeDocument.info.headline;
 alert ("Autor: " + aut + "; Überschrift: " + head, "Metadaten");

 

Variable & Eingabe

var text = prompt("Gib hier ein womit die Variable gefüllt werden soll…!");
 alert (text);

 

Neue Ebene erstellen

var neueEbene = activeDocument.artLayers.add();
 neueEbene.name = "Meine Ebene";

 

Fehlermeldung unterdrücken

try {
 HIER CODE REIN
 }
 };
 } catch (e) {}

 

Ebene mit darunterliegende reduzieren

activeDocument.activeLayer.merge();

 

Datei schließen ohne speichern

app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);  

 

Auswahl aufheben

app.activeDocument.selection.deselect()

 

Auswahl umkehren

app.activeDocument.selection.invert()

 

Modus wechseln (RGB / CMYK etc)

app.activeDocument.changeMode(ChangeMode.RGB);

 

Auswahl ​mit Vordergrund – oder Hintergrundfarbe füllen

app.activeDocument.selection.fill(app.foregroundColor)
app.activeDocument.selection.fill(app.backgroundColor)

 

Ein Bild mit dem gleichen Namen aus einem anderen Ordner öffnen

var targetDir = app.activeDocument.path + "/";
 var docName = app.activeDocument.name;
 var targetDocName = docName.substring(0, docName.lastIndexOf("."));
 var targetFile = new File(targetDir + "/ORDNERNAME/" +targetDocName + ".jpg");
 var doc = open(targetFile);

 

Aktion wenn Bild – Höhe größer ist als 2000px

if (app.activeDocument.height > '2000')
     {
     doAction("action1","SCRIPT1");
     }
 else
     {
 doAction("action2","SCRIPT1");
     };

 

Teil des Namens ersetzen

var docName = app.activeDocument.name.replace("ALTER_TEILNAME","NEUER_TEILNAME");

 

Datei öffnen

app.open(File.openDialog("Datei wählen"));

 

Ordner anlegen, wo das geöffnete Bild gespeichert ist

var folder1 = Folder(app.activeDocument.path + "/../111" + "/../2222" );
 if(!folder1.exists) folder1.create();

 

JPG Speichern

app.bringToFront();
 var targetDir = app.activeDocument.path + "/";
 var docName = app.activeDocument.name;
 var targetDocName = docName.substring(0, docName.lastIndexOf("."));
 var targetFile = new File(targetDir + targetDocName);
 saveAs(targetFile);
 function saveAs(filename)
 {
 var saveFile = new File(filename + ".jpg");
 jpgSaveOptions = new JPEGSaveOptions();
 jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
 jpgSaveOptions.embedColorProfile = true;
 jpgSaveOptions.quality = 12;
 app.activeDocument.saveAs(saveFile, jpgSaveOptions, true, Extension.LOWERCASE);
 }

 

TIFF Speichern

target photoshop
 var targetDir= app.activeDocument.path + "/"
 var docName = app.activeDocument.name;
 var targetDocName = docName.substring(0, docName.lastIndexOf("."));
 var targetFile = new File(targetDir + targetDocName);
 saveAs(targetFile);
 function saveAs(filename)
 {
     var saveFile = new File(filename + ".tif");
     tiffSaveOptions = new TiffSaveOptions();   
     tiffSaveOptions.embedColorProfile = true;   
     tiffSaveOptions.alphaChannels = true;   
     tiffSaveOptions.layers = true;  
     tiffSaveOptions.imageCompression = TIFFEncoding.JPEG;  
     tiffSaveOptions.jpegQuality=12;  
     activeDocument.saveAs(saveFile, tiffSaveOptions, true, Extension.LOWERCASE);   
 }

 

PNG Speichern

main();
 function main()
 {
 var Name = app.activeDocument.name.replace(/.[^.]+$/, ''); var Path = "Speicherort-angeben"; // Save as PNG SaveFile = File(Path + "/" + Name +".png"); SavePNG(SaveFile);
 }
 function SavePNG(saveFile)
 {
   var pngSaveOptions = new PNGSaveOptions();
   pngSaveOptions.compression = 9
   pngSaveOptions.interlaced = false
   pngSaveOptions.embedColorProfile = true
   activeDocument.saveAs(saveFile, pngSaveOptions, true, Extension.LOWERCASE);
 }