// openFolderTemplate.jsx modified to FileNameToText - in the process part, the code should process filenames to text
// Copyright 2007
// Written by Jeffrey Tranberry
// Photoshop for Geeks Version 1.0
/*
Description:
This script is a template script that will
open and process a folder of images
*/
// enable double clicking from the
// Macintosh Finder or the Windows Explorer
#target photoshop
// Make Photoshop the frontmost application
// in case we double clicked the file
app.bringToFront();
///////////////////////////
// SET-UP //
///////////////////////////
// A list of file extensions to skip, keep them lower case
gFilesToSkip = Array( "db", "xmp", "thm", "txt", "doc", "md0", "tb0", "adobebridgedb", "adobebridgedbt", "bc", "bct" );
// Pops open a dialog for the user to
// choose the folder of documents to process
var inputFolder = Folder.selectDialog("Select a folder of documents to process");
// Pops open a dialog for the user to
// set the output folder
var outputFolder = Folder.selectDialog("Select a folder for the output files");
///////////////////////
// MAIN //
//////////////////////
// Open Folder of Images
OpenFolder();
// show the path to an output folder
alert(outputFolder);
///////////////////////////
// FUNCTIONS //
///////////////////////////
// Given the a Folder of files, open them
function OpenFolder() {
var filesOpened = 0;
var fileList = inputFolder.getFiles();
for ( var i = 0; i < fileList.length; i++ ) {
// Make sure all the files in the folder are compatible with PS
if ( fileList[i] instanceof File && ! fileList[i].hidden && ! IsFileOneOfThese( fileList[i], gFilesToSkip )) {
app.open( fileList[i] ); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
filesOpened++;
/////////////////////////////////////
// Put all your processing functions... //
/////////////////////////////////////
// set rulers to pixels and save original for resetting
var originalUnits = app.preferences.rulerUnits
app.preferences.rulerUnits = Units.INCHES;
// app.documents.add( 2, 2 );
app.documents.open( fileList[i] ); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// add the pixel position for the left side of your text block below
var textLeftPosition= 0.25
// add the pixel position for the bottom of your text block below
var textBottomPosition= 0.25
/////////////////////////////////////////////////////////////////////
var doc = app.activeDocument;// make a reference to the doc
var topLayer = app.activeDocument.layers[0];// make a reference to the top layer
if ( doc.activeLayer != topLayer ) {// if the top layer is not the active layer
var cv = topLayer.visible;// store the visible state
app.activeDocument.activeLayer = topLayer;// make active, which makes visible
topLayer.visible = cv;// so retore visible state
}
/////////////////////////////////////////////////////////////////////
var typeLayer = app.activeDocument.artLayers.add();
typeLayer.name = app.activeDocument.name;
typeLayer.kind = LayerKind.TEXT;
typeLayer.textItem.size = 48;
typeLayer.textItem.position = [textLeftPosition, textBottomPosition];
typeLayer.textItem.contents = typeLayer.name;
// return units to original
app.preferences.rulerUnits = originalUnits
saveFile = new File(outputFolder+"/text_"+typeLayer.name+".png");
saveOptions = new PNGSaveOptions();
app.activeDocument.saveAs(saveFile, saveOptions, true,Extension.LOWERCASE);
// Cloes the file without saving
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
////////////////////////////////////////////
// ...in the area between these two comments. //
////////////////////////////////////////////
}
}
return filesOpened;
}
// given a file name and a list of extensions
// determine if this file is in the list of extensions
function IsFileOneOfThese( inFileName, inArrayOfFileExtensions ) {
var lastDot = inFileName.toString().lastIndexOf( "." );
if ( lastDot == -1 ) {
return false;
}
var strLength = inFileName.toString().length;
var extension = inFileName.toString().substr( lastDot + 1, strLength - lastDot );
extension = extension.toLowerCase();
for (var i = 0; i < inArrayOfFileExtensions.length; i++ ) {
if ( extension == inArrayOfFileExtensions[i] ) {
return true;
}
}
return false;
}