4

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 perfectly, however my filenames have leading numbers (01, 02, 03, etc) to keep them in a specific order. It's only ever two digits for the leading numbers.

Is it possible to edit this script to strip the first two numbers from the filename when putting it on my image? I want the numbers to stay in the filename, just not in the image.

For example: 01Firstfile = Firstfile when 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've searched and searched for an answer and finally decided to just ask to see if someone can help me. I apologize if this is already been answered and I just couldn't find it.

Below is a portion of the script. I've 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;

1 Answer 1

2

Change:

myTextRef.contents = fileNameNoExtension;

To:

myTextRef.contents = fileNameNoExtension.substring(2);

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.