Here's a little tip for my fellow designers. If you've ever used Photoshop's "Export Layers to Files" or "Export Layer Comps to Files" functions you'll likely have noticed how limited your options are when it comes assigning file names to the images that Photoshop outputs. By default, Photoshop prompts you for a filename prefix and then auto-generates the rest of the filename, adding in a zero-padded number sequence, 000X, that many people find unnecessary. So for example, let's say that you would like to export three layer comps named "comp1", "comp2", and "comp3". If you choose "project" for your filename prefix, you would end up with a series of output files named
While this naming convention may work for some, designers working on projects that involve large numbers of generated files may find themselves having to manually edit these filenames to fit within a broader project-wide file naming scheme. Of course, there are plenty of batch renaming tools out there that can make this process easier. But wouldn't it be better if you could set your own file naming convention from the start? With a little hackery, you can.
Hack your Photoshop filenames
Before you do anything with this file, make a copy and save it somewhere outside of the Adobe Photoshop CC 2015 folder. Do not skip this step. You need to have a backup in case anything goes wrong while you are monkeying with Photoshop's helper scripts.
Now that you have a backup safely stashed away, open "Layer Comps To Files.jsx" within TextEdit (or Notepad for Windows users). Here you have the code responsible for spitting out your layer comps as image files. Hit Command-F (Control-F on Windows) to bring up the search bar. Search for "zeroSuppress". The first result should take you to this line:
fileNameBody += "_" + zeroSuppress(compsIndex, 4);
This single line is responsible for adding the zero-padded number in your filenames. If you comment this line out (prepend the line with two forward-slashes), Photoshop will go from generating your filenames like this:
That's all there is to it. Save the file, re-open Photoshop and try exporting some layer comps. If this isn't quite the result that you want, you can alter this section of code in a number of different ways to suit your needs. Say you want your filenames to match exactly the names that you gave to your layer comps - nothing more or less. In this case, after completing the previous steps, find the line directly below the zeroSuppress line and change it from this:
fileNameBody += "_" + compRef.name;
fileNameBody += compRef.name;
Now when you go to export your layer comps, leave the "Prefix" section of the dialog empty and your image files will be assigned the exact same names as you gave to your layer comps (plus file extension type).
If you are using the 2015 version of Photoshop CC, these steps should work for you. Earlier versions can be hacked in a similar way but be aware that the code does vary between versions, so Photoshop CC 2014 and earlier will require a slightly different set of adjustments. Remember, if at any time something goes wrong and you find yourself running into error messages you can always revert back using the "Layer Comps To Files.jsx" copy that you made at the beginning. Simply close out of Photoshop and replace your edited version of the file with your copy of the original.
I spend a fair amount of time in Photoshop building static comps for what will eventually become animations. This involves setting up many panels, often sharing assets between them and creating incremental changes from panel to panel. Producing and exporting all of these panels would be a pain if it weren't for layer comps. (Now we have an even better solution with PS 2015's Artboards feature, but that's the subject of another post.) Being able to set up my own custom naming convention for batch file exports is the final piece of that puzzle. Of course, while effective, this method is a poor substitute for true in-app control over your naming. Here's hoping Adobe takes this into account in future Photoshop versions.