4 Replies Latest reply on Oct 24, 2017 1:27 PM by Chuck Uebele

    Stripping first 4 characters from an 8 character file name in a script?

    Fjuds

      I have a script to add the file number to the front of the image for proofing. I would like to remove the first 4 characters in the 8 character file name in the script.

      I don't code so I'm looking for the lines of code to add to the script.

      It would help reduce paperwork errors when we show portraits.

       

      Thanks for any help,

      Fjuds

       

      // this script is a variation of the script addTimeStamp.js that is installed with PH7
      
      
      if ( documents.length > 0 )
      {
        var originalRulerUnits = preferences.rulerUnits;
        preferences.rulerUnits = Units.PIXELS;
      
        try
        {
        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 bottom center
        myTextRef.position = new Array( docRef.width / 3, docRef.height / 1.03 );
        myTextRef.size = 60;
        }
        catch( e )
        {
        // An error occurred. Restore ruler units, then propagate the error back
        // to the user
        preferences.rulerUnits = originalRulerUnits;
        throw e;
        }
      
      
        // Everything went Ok. Restore ruler units
        preferences.rulerUnits = originalRulerUnits;
      }
      else
      {
        alert( "You must have a document open to add the filename!" );
      }