1. // openFolderTemplate.jsx modified to FileNameToText - in the process part, the code should process filenames to text
  2. // Copyright 2007
  3. // Written by Jeffrey Tranberry
  4. // Photoshop for Geeks Version 1.0
  5.  
  6. /*
  7. Description:
  8. This script is a template script that will
  9. open and process a folder of images
  10. */
  11.  
  12. // enable double clicking from the
  13. // Macintosh Finder or the Windows Explorer
  14. #target photoshop
  15.  
  16. // Make Photoshop the frontmost application
  17. // in case we double clicked the file
  18. app.bringToFront();
  19.  
  20.  
  21. ///////////////////////////
  22. //       SET-UP          //
  23. ///////////////////////////
  24.  
  25.  
  26. // A list of file extensions to skip, keep them lower case
  27.  
  28.     gFilesToSkip = Array( "db", "xmp", "thm", "txt", "doc", "md0", "tb0", "adobebridgedb", "adobebridgedbt", "bc", "bct" );
  29.  
  30.  
  31. // Pops open a dialog for the user to
  32. // choose the folder of documents to process
  33.  
  34.     var inputFolder = Folder.selectDialog("Select a folder of documents to process");
  35.  
  36.  
  37. // Pops open a dialog for the user to
  38. // set the output folder
  39.  
  40.     var outputFolder = Folder.selectDialog("Select a folder for the output files");
  41.  
  42.  
  43.  
  44. ///////////////////////
  45. //         MAIN          //
  46. //////////////////////
  47.  
  48.  
  49.  
  50. // Open Folder of Images
  51.    
  52.     OpenFolder();
  53.  
  54.  
  55. // show the path to an output folder
  56.    
  57.     alert(outputFolder);
  58.  
  59.  
  60.  
  61. ///////////////////////////
  62. //       FUNCTIONS       //
  63. ///////////////////////////
  64.  
  65.  
  66.  
  67. // Given the a Folder of files, open them
  68.  
  69. function OpenFolder() {
  70.         var filesOpened = 0;
  71.         var fileList = inputFolder.getFiles();
  72.         for ( var i = 0; i < fileList.length; i++ ) {
  73.                    // Make sure all the files in the folder are compatible with PS
  74.                 if ( fileList[i] instanceof File && ! fileList[i].hidden && ! IsFileOneOfThese( fileList[i], gFilesToSkip )) {
  75.                         app.open( fileList[i] ); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  76.                         filesOpened++;
  77.                
  78.                
  79.                     /////////////////////////////////////
  80.                     // Put all your processing functions... //
  81.                     /////////////////////////////////////
  82.                    
  83. // set rulers to pixels and save original for resetting
  84. var originalUnits = app.preferences.rulerUnits
  85.  
  86.                     app.preferences.rulerUnits = Units.INCHES;
  87. //  app.documents.add( 2, 2 );
  88. app.documents.open( fileList[i] ); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  89.  
  90. // add the pixel position for the left side of your text block below
  91. var textLeftPosition= 0.25
  92.  
  93. // add the pixel position for the bottom of your text block below
  94. var textBottomPosition= 0.25
  95.  
  96. /////////////////////////////////////////////////////////////////////
  97. var doc = app.activeDocument;// make a reference to the doc
  98. var topLayer = app.activeDocument.layers[0];// make a reference to the top layer
  99. if ( doc.activeLayer != topLayer ) {// if the top layer is not the active layer
  100.     var cv = topLayer.visible;// store the visible state
  101.     app.activeDocument.activeLayer = topLayer;// make active, which makes visible
  102.     topLayer.visible = cv;// so retore visible state
  103.     }
  104. /////////////////////////////////////////////////////////////////////
  105.  
  106. var typeLayer = app.activeDocument.artLayers.add();
  107.  
  108. typeLayer.name = app.activeDocument.name;
  109. typeLayer.kind = LayerKind.TEXT;
  110. typeLayer.textItem.size = 48;
  111. typeLayer.textItem.position = [textLeftPosition, textBottomPosition];
  112. typeLayer.textItem.contents = typeLayer.name;
  113.  
  114. // return units to original
  115. app.preferences.rulerUnits = originalUnits
  116.                        
  117.                        
  118. saveFile = new File(outputFolder+"/text_"+typeLayer.name+".png");
  119. saveOptions = new PNGSaveOptions();
  120.  
  121.  
  122. app.activeDocument.saveAs(saveFile, saveOptions, true,Extension.LOWERCASE);                    
  123.                        
  124.                         // Cloes the file without saving
  125.                         app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
  126.                    
  127.                     ////////////////////////////////////////////
  128.                     // ...in the area between these two comments. //
  129.                     ////////////////////////////////////////////
  130.  
  131.  
  132.                 }
  133.  
  134.         }
  135.         return filesOpened;
  136. }
  137.  
  138.  
  139. // given a file name and a list of extensions
  140. // determine if this file is in the list of extensions
  141.  
  142. function IsFileOneOfThese( inFileName, inArrayOfFileExtensions ) {
  143.     var lastDot = inFileName.toString().lastIndexOf( "." );
  144.     if ( lastDot == -1 ) {
  145.         return false;
  146.     }
  147.     var strLength = inFileName.toString().length;
  148.     var extension = inFileName.toString().substr( lastDot + 1, strLength - lastDot );
  149.     extension = extension.toLowerCase();
  150.     for (var i = 0; i < inArrayOfFileExtensions.length; i++ ) {
  151.         if ( extension == inArrayOfFileExtensions[i] ) {
  152.             return true;
  153.         }
  154.     }
  155.     return false;
  156. }