title: Add file name to image on Photoshop with JS Script
body: <p>I would like to add the filename to a image using Photoshop</p>
  
  <p>Example file name</p>
  
  <blockquote>
    <p>image 123-back.jpg
    image 123-front.jpg</p>
  </blockquote>
  
  <p>I would like the to remove the -back and -front from the name added to the image</p>
  
  <p>So far I can add the file name but cannot remove the -back and -front</p>
  
  <p>This is the code I have so far </p>
  
  <pre><code>// this script is a variation of the script addTimeStamp.js that is installed with PH7
  
  if ( documents.length &gt; 0 )
  {
      var originalDialogMode = app.displayDialogs;
      app.displayDialogs = DialogModes.ERROR;
      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 &gt; 1 ) {
              fileNameNoExtension.length--;
          }
          fileNameNoExtension = fileNameNoExtension.join(".");
  
          myTextRef.contents = '*' + fileNameNoExtension +'*';
  
          // Set the position of the text  percentages from left first, then from top
          myTextRef.position = new Array( docRef.width / 2.5, docRef.height / 6 );
          myTextRef.size = 15.76;
      }
      catch( e )
      {
          // An error occurred. Restore ruler units, then propagate the error back
          // to the user
          preferences.rulerUnits = originalRulerUnits;
          app.displayDialogs = originalDialogMode;
          throw e;
      }
  
      // Everything went Ok. Restore ruler units
      preferences.rulerUnits = originalRulerUnits;
      app.displayDialogs = originalDialogMode;
  }
  else
  {
      alert( "You must have a document open to add the filename!" );
  }
  </code></pre>