4 Replies Latest reply on May 18, 2015 8:27 AM by mariap14286444

    Editted file name to layer

    mariap14286444 Level 1

      I have a PSD file called "WEB-MUG-12345" - I am able to use a script to put that name into that same PSD file and use actions to change font, size, placement.

       

      I need to insert asterisks so in my PSD file it will read "*WEB-MUG-12345*". I am not able to insert asterisks like I usually edit text in Photoshop. I cannot have a jpeg layer of asterisks because I need to change the font to a barcode font, and this barcode must be scanned so the asterisks must be as proper text with the "WEB-MUG-12345".

       

      When I used actions to manually insert asterisks, it saved the "12345" whereas I will need to do an automated batch sequence so this number will change with each new file.

       

      This is the script I am currently using.

       

      Many thanks in advance!

       

      // this script is a variation of the script addTimeStamp.js that is installed with PH7

       

      if ( documents.length > 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 > 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 / 3.5 );

              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!" );

      }

       

       

      Courtesy of Add File Name as Text Layer « Julieanne Kost's Blog

        • 1. Re: Editted file name to layer
          JJMack Most Valuable Participant

          Can not follow what you have written  asterisks in file names are wild cards and can be satisfied by any character string of any length also "." is a valid character in a  file name. For example "John J. McAssey Jr..jpg" is a valid filename.  I use file manes for many things and if I want files to sorts a particular way I use a filename prefix sequence number followed be a "#".  I Isolate names this way

           

          // Isolate Image name

            var Name =  decodeURI(fileList[i]).replace(/\.[^\.]+$/, ''); // strip the extension off

            var imagePath = "";

            while (Name.indexOf("/") != -1 ) { // Strip Path

                 imagePath= imagePath + Name.substr(0, Name.indexOf("/") + 1);

                 Name = Name.substr(Name.indexOf("/") + 1 ,);

                 }

            if (Name.indexOf("#") != -1 ) { // Strip any prefix sequence number off

                 prefixlist[imageNumber - 1] = Name.substr(0,Name.indexOf("#") );

                 Name = Name.substr(Name.indexOf("#") + 1 ,);

                 }

          • 2. Re: Editted file name to layer
            mariap14286444 Level 1

            Hi,

             

            Thanks for your response, but that's not what I need. That script doesn't work and I'm unable to place it into my own script to work.

             

            I don't need asterisks in the file name itself, I just need it visible on the canvas, so that would probably require putting them into the script.

             

            I hope this clears it up a bit. It's hard to explain.

            • 3. Re: Editted file name to layer
              Chuck Uebele Adobe Community Professional & MVP

              If you just want the asterisks in the file name, try:

               

              myTextRef.contents = '*' + fileNameNoExtension +'*';
              
              • 4. Re: Editted file name to layer
                mariap14286444 Level 1

                Yes!!! Thank you so much! I really appreciate everyone's help, thank you