4 Replies Latest reply on Feb 11, 2013 7:26 AM by asmcleod

    Layers to files: replace spaces with underscores

    asmcleod

      How can I update the script to replace spaces with underscores on export? I assume I need to add a line somehwere between 183-195 but I don't know what it needs to be. Thanks in advance.

        • 1. Re: Layers to files: replace spaces with underscores
          JJMack Most Valuable Participant

          Where did you get the Layers to files script. Photoshop versions ship with a "Export Layers To Files.jsx" CS6 lines 183-195 look like this I see nothing about filename

           

            var layerSetsCount = app.documents[docName].layerSets.length;

           

                   if ((layerCount <= 1)&&(layerSetsCount <= 0)) {

                      if ( DialogModes.NO != app.playbackDisplayDialogs ) {

                          alert( strAlertNeedMultipleLayers );

                                  return 'cancel'; // quit, returning 'cancel' (dont localize) makes the actions palette not record our script

                      }

                  } else {

           

                      var rememberMaximize;

                      var needMaximize = exportInfo.psdMaxComp ? QueryStateType.ALWAYS : QueryStateType.NEVER;

                      if ( exportInfo.fileType == psdIndex && app.preferences.maximizeCompatibility != needMaximize ) {

                          rememberMaximize = app.preferences.maximizeCompatibility;

          1 person found this helpful
          • 2. Re: Layers to files: replace spaces with underscores
            JJMack Most Valuable Participant

            Line  1029-1032 in Export Layer to Files look more like what you may be looking for. You may be able to add " " to line 1032 I do not know regular expression syntax this may work  (/[:\/\\*\?\"\<\>\|\ ]/g, "_")

             

                   var fileNameBody = fileNamePrefix;

                    fileNameBody += "_" + zeroSuppress(i, 4);

                    fileNameBody += "_" + layerName;

                    fileNameBody = fileNameBody.replace(/[:\/\\*\?\"\<\>\|]/g, "_");  // '/\:*?"<>|' -> '_'

            1 person found this helpful
            • 3. Re: Layers to files: replace spaces with underscores
              conroy Level 5

              In line 1032, insert a backslash and space immediately before the characters ']/g'.

              Also insert a space in the equivalent location of the comment for completeness.

              The result will look like:

               

              Screen shot 2013-02-09 at 00.07.04.png

              • 4. Re: Layers to files: replace spaces with underscores
                asmcleod Level 1

                I was looking in the wrong script. I had the Layer COMPS to files script, but you are all correct. I need the Export Layers to Files script. Thanks for the responses.