Photoshop Script Add Filename to Image as Text, But Remove '-' character
I found a script that will take the filename of my image and put it on the image, minus the file extension. I have added this to an action, which works exactly how I want it, however my filenames have '-' characters in them.
Is it possible to remove the '-' characters in the script? I haven't been able to get the replace function to work. (which I need).
This is the code that is working right now:
// Now create a text layer at the front
var myLayerRef = docRef.artLayers.add();
myLayerRef.kind = LayerKind.TEXT;
myLayerRef.name = "Filename";
var myTextRef = myLayerRef.textItem;
// strip the extension off
var fileNameNoExtension = docRef.name;
fileNameNoExtension = fileNameNoExtension.split( "." );
if ( fileNameNoExtension.length > 1 ) {
fileNameNoExtension.length--;
}
fileNameNoExtension = fileNameNoExtension.join(".");
myTextRef.contents = fileNameNoExtension.substring(2);
// myTextRef.contents = fileNameNoExtension.replace(/^-/i, '');
// off set the text to be in the middle
myTextRef.position = new Array( docRef.width / 2, docRef.height / 2 );
myTextRef.size = 28;
}
