Photoshop Script Add filename to image as text, but remove first two characters

I found a script that will take the filename of my image and put it in the image minus the file extension. I added this to an action which works great, however my filenames have leading numbers (01, 02, 03, etc.) to keep them in a specific order. These are only two digits for the leading numbers.

Can I edit this script to remove the first two numbers from the file name when placed on my image? I want the numbers to stay in the filename, not in the image.

For example: 01Firstfile = First file, if placed on the image.

Here's the link where I found the script: http://blogs.adobe.com/jkost/2010/09/add-file-name-as-text-layer.html

I searched and searched for an answer and finally decided to just ask if anyone can help me. I apologize if this has already been answered and I just couldn't find it.

Below is part of the script. I tried to put the whole script here, but it keeps giving me an error.

var docRef = activeDocument;

    // 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;

    // off set the text to be in the middle
    myTextRef.position = new Array( docRef.width / 2, docRef.height / 2 );
    myTextRef.size = 20;

      

+3


source to share


1 answer


Edit:

myTextRef.contents = fileNameNoExtension;



To:

myTextRef.contents = fileNameNoExtension.substring(2);

+1


source







All Articles