A few years ago, a fellow named Brian Dorn got in touch with me. He was working on his doctoral dissertation at Georgia Tech and he needed participants. I met him in Atlanta and found out that his study was about scripting with Photoshop. That was the first I'd ever heard of Adobe Photoshop Scripting.
A few weeks ago when I started working on a new word game This2That for Mobile Magic Developers, I needed to generate 38 tiles with letters, numbers, and punctuation. The task was tedious and the macros just couldn't make it any easier. Then I realized I had the embossing all wrong and I had to start over!
Frustrated, I tried to think of a better way. I remembered Brian Dorn and I started looking into this Adobe Photoshop JavaScript thing. I was very pleased when 15 minutes of script became an easily reusable tile generating utility. Now, I can take any PSD, open it up, select any text layer, and have the script generate a PNG for each letter I need
I thought this little known feature would make for interesting reading for both programmers and designers so here's my script:
// call the method that does all of the work
main();
// wrap the code in a method to make it easier to debug
function main() {
// make sure you're working in a document and have a text layer selected
if (!activeDocument || !activeDocument.activeLayer || activeDocument.activeLayer.kind != LayerKind.TEXT)
{
alert("Please select a document and a target text layer.");
return;
}
// set up some information about the current file
var textLayer = activeDocument.activeLayer;
var path = activeDocument.path;
var fileName = activeDocument.name;
// remove the extension on the file name
var extensionPosition;
if (extensionPosition = fileName.lastIndexOf('.'))
fileName = fileName.substr(0, extensionPosition);
// get a good place to put the file
var outputFolder = Folder.selectDialog("Select a target folder.", path);
// set up the letters we want images for
var characterMap = [
["question", "?"]
];
// and add the lowercase alphabet and numbers
characterMap = characterMap.concat(getAsciiRange(97, 26), getAsciiRange(48, 10));
// for each character, update the selected text layer and save a file
for (var i = 0; i < characterMap.length; i++)
{
var character = characterMap[i][1];
var fileSuffix = characterMap[i][0];
textLayer.textItem.contents = character;
var file = new File(outputFolder + "/" + fileName + "_" + fileSuffix + ".png");
var options = new PNGSaveOptions();
options.interlaced = false;
activeDocument.saveAs(file, options, true, Extension.LOWERCASE);
}
};
// a little helper method to make a range of letters and their
// filename extensions
function getAsciiRange(from, count) {
var result = [];
for (var i = 0; i < count; i++)
{
var character = String.fromCharCode(i + from);
result.push([character, character.toUpperCase()]);
}
return result;
}
© 2008 , D. Patrick Caldwell, President, Autopilot Consulting, LLC

A while back I developed a helper method that I've been using to aid me in computing good hash values from sets of properties for an object. I was writing a
Visual Studio 2005 came with a slew of .net and .net compiler features. One of those features that I particularly enjoy is the 
I went on my honeymoon with my beautiful wife last week and the week before. Having a little time off of work gave me the opportunity to get some work done :). I've been wanting for a while to develop a survey to find out
I have an old website where I keep most of my bookmarklets. I'm planning on deprecating that site and just putting up some personal stuff (since I don't do what that site says I do anymore).


click for more information