Skip to main content
Todd_Morgan
Legend
March 31, 2023
Open for Voting

Export as... add prefix function to auto use PSD filename in output files

  • March 31, 2023
  • 11 replies
  • 3484 views

Would be great to have the Export as... function the ability to take the filename and add into the export files filename, and /or ability to add custom prefix!! Already a Suffix field exists. PLEASE!!!!!!!!!!!!!

11 replies

Stephen Marsh
Community Expert
Community Expert
November 11, 2023

Nobody has denied the usefulness of the feature request.

 

We are all end-users here, not Adobe staff.

 

All we can do is make pragmatic suggestions to work within the framework provided by Adobe for now, until further options are possibly added.

Todd_Morgan
Legend
November 11, 2023

@Think Seed Thank you and exactly... glad there are other likeminded designers out there [abuse removed].

Inspiring
November 11, 2023

Just my two cents that I'd love this, too. I have to create artwork daily across mutlitple social networks. I label each file according to the part number. I want all the social media files to have the part number as the prefix so when I go to update all the social media accounts, they're all in one spot in alphabetical order. I'd prefer they are all named with a prefix: "Part0001Insta" "Part0001Facebook". The way it works now as a Suffix, it is alphabetized first by the artboard names "InstaPart0001" "FacebookPart0001". The suggestions that other people are making like using Bridge, or to somehow rename after the fact defeats the purpose of this feature request to begin with. I have a very specific workflow and having this feature would be a HUGE time saver. As the OP stated, it already has SUFFIX as an option. Doesn't seem difficult to make PREFIX an option as well. When you're creating literally thousands of files a month, any time saving is a plus.

Todd_Morgan
Legend
April 10, 2023

I already have several ways to do stuff outside of Photoshop - hence the ask to have it native in the software. @mglush when it comes to "complaining" about how bad Bridge is - that's a whole other pot to get into, and well noted by users.

Stephen Marsh
Community Expert
Community Expert
April 7, 2023

For sake of completeness, for those that do wish to do this via Adobe Bridge's Batch Rename Tool, here are some visual examples:

 

Method 1: Delete the suffix and manually add the prefix:

 

 

or

 

Method 2: Swap the suffix for the prefix

 

Find:

(^.+)(_)(.+)(\.[^\.]+$)

Replace:

$3$2$1$4

 

 

 

Restore the preserved filename:

 

Stephen Marsh
Community Expert
Community Expert
April 7, 2023

Due to underwhelming demand, I have updated the script to a 1.1 version to include the ability to restore the preserved filename metadata, just in case the batch renaming doesn't go to plan. Simply hold down the ALT/OPT key when running the script.

 

/*

Rename Files in Folder Swapping Suffix to Prefix.jsx
https://community.adobe.com/t5/photoshop-ecosystem-ideas/export-as-add-prefix-function-to-auto-use-psd-filename-in-output-files/idi-p/13694701
v1.1, 7th April 2023, Stephen Marsh

Notes: 
* Change the RegEx capture group underscore (_) to a hyphen (-) or another unique separator as required
* The original filename will be set in the preserved filename metadata to facilitate the restoration of the original filename via Adobe Bridge, ExifTool etc.

Changelog:
* v1.0: 2nd April 2023 - initial release
* v1.1: 7th April 2023 - Added an option to restore the preserved filename by holding down the ALT/OPT key when running the script

Batch renames files from:

Filename-1_Suffix.png
Filename-2_Suffix.png
Filename-3_Suffix.png

To:

Suffix_Filename-1.png
Suffix_Filename-2.png
Suffix_Filename-3.png

*/

#target photoshop

try {
    
    // Hold down ALT/OPT to restore the preserved filename
    if (ScriptUI.environment.keyboardState.altKey) {

        if (confirm("Do you really want to restore the original filenames?")) {

            var theInputFolder = Folder.selectDialog("Please select the folder to restore the original filenames:");
            // Add or remove supported file types as required
            var theInputFiles = theInputFolder.getFiles(/\.(gif|png|jpe?g|tif?f|psd|psb)$/i);
            for (var i = 0; i < theInputFiles.length; i++) {
                try {
                    // Get the preserved filename metadata
                    var xmpFile = new XMPFile(theInputFiles[i].fsName, XMPConst.FILE_UNKNOWN, XMPConst.OPEN_FOR_READ);
                    var xmpMeta = xmpFile.getXMP();
                    var preserved = xmpMeta.getProperty(XMPConst.NS_XMP_MM, "PreservedFileName");
                    // Rename the files
                    if (preserved != undefined) {
                        theInputFiles[i].rename(preserved);
                    } else {
                        alert("One or more files weren't renamed due to missing preserved filename metadata!");
                    }
                
                } catch (error) {
                    alert(error + ', Line: ' + error.line);
                }
            }
            app.beep();
        }

    // Rename using the suffix as the prefix
    } else {

        if (confirm("Do you really want to swap the filename suffix to a prefix?")) {

            var theInputFolder = Folder.selectDialog("Please select the folder to swap the filename suffix to a prefix:");
            // Add or remove supported file types as required
            var theInputFiles = theInputFolder.getFiles(/\.(gif|png|jpe?g|tif?f|psd|psb)$/i);
            for (var i = 0; i < theInputFiles.length; i++) {
                // Set the original filename to the preserved filename metadata
                setPreservedFilenameMeta(theInputFiles[i], theInputFiles[i].displayName);
                // Swap the suffix for the prefix
                var theRegEx = theInputFiles[i].name.replace(/(^.+)(_)(.+)(\.[^\.]+$)/, '$3$2$1$4');
                // Rename the files using the suffix as the prefix
                theInputFiles[i].rename(theRegEx);
            }
            app.beep();
        }
    }

} catch (error) {
    alert(error + ', Line: ' + error.line);
}


function setPreservedFilenameMeta(theFile, theName) {
    // Get the preserved filename metadata
    if (!ExternalObject.AdobeXMPScript) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
    var xmpFile = new XMPFile(File(theFile).fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);
    var xmp = xmpFile.getXMP();
    xmp.setProperty('http://ns.adobe.com/xap/1.0/mm/', 'PreservedFileName', theName), xmp.rawData = xmp.serialize();
    if (xmpFile.canPutXMP(xmp)) {
        xmpFile.putXMP(xmp);
    }
    xmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
}

 

Stephen Marsh
Community Expert
Community Expert
April 2, 2023

@Todd_Morgan wrote:

First off - Adobe Bridge is a PITA.


 

I can only presume that you don't like using the Adobe Bridge Batch Rename tool... So here is a Photoshop script to batch rename a folder of files meeting the following condition of a unique separator, in this case, an underscore character. This is easily adapted to a hyphen or another unique character.

 

Filename-1_Suffix.png

To:

Suffix_Filename-1.png
 
The script will additionally preserve the original filename in the file metadata for easy recovery of the original filename.

 

 

/*

Rename Files in Folder Swapping Suffix to Prefix.jsx
https://community.adobe.com/t5/photoshop-ecosystem-ideas/export-as-add-prefix-function-to-auto-use-psd-filename-in-output-files/idi-p/13694701
v1.0, 2nd April 2023, Stephen Marsh

Notes: 
* Change the RegEx capture group underscore (_) to a hyphen (-) or another unique separator as required
* The original filename will be set in the preserved filename metadata to facilitate restoration of the original filename via Adobe Bridge, ExifTool etc.
* To do: Add an option to restore the preserved filename via the script

Batch renames files from:

Filename-1_Suffix.png
Filename-2_Suffix.png
Filename-3_Suffix.png

To:

Suffix_Filename-1.png
Suffix_Filename-2.png
Suffix_Filename-3.png

*/

#target photoshop

var theInputFolder = Folder.selectDialog("Please select the folder to swap the filename suffix to prefix:");
var theInputFiles = theInputFolder.getFiles(/\.(gif|png|jpe?g|tif?f|psd|psb)$/i);
for (var i = 0; i < theInputFiles.length; i++) {
    setPreservedFilenameMeta(theInputFiles[i], theInputFiles[i].displayName);
    var theRegEx = theInputFiles[i].name.replace(/(^.+)(_)(.+)(\.[^\.]+$)/, '$3$2$1$4');
    theInputFiles[i].rename(theRegEx);
}
app.beep();


function setPreservedFilenameMeta(theFile, theName) {
    if (!ExternalObject.AdobeXMPScript) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
    var xmpFile = new XMPFile(File(theFile).fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);
    var xmp = xmpFile.getXMP();
    xmp.setProperty('http://ns.adobe.com/xap/1.0/mm/', 'PreservedFileName', theName), xmp.rawData = xmp.serialize();
    if (xmpFile.canPutXMP(xmp)) {
        xmpFile.putXMP(xmp);
    }
    xmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
}

 

  1. Copy the code text to the clipboard
  2. Open a new blank file in a plain-text editor (not in a word processor)
  3. Paste the code in
  4. Save as a plain text format file – .txt
  5. Rename the saved file extension from .txt to .jsx
  6. Install or browse to the .jsx file to run (see below)

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html#Photoshop

Stephen Marsh
Community Expert
Community Expert
April 1, 2023
quote

I work with files with several many artboards. And outputting them all through Artboards to Files works but for some reason takes forever. Using the export as... is fast. And much preferred - but it won't save with the PSD filename or allow to create a Prefix - suffic only.


By @Todd_Morgan

 

I have added my vote for adding a prefix option.

 

Adding a custom prefix by typing into the field is different from using the filename. Perhaps if they added the ability to use a code such as "@@docname@@" or something, then it could use the document name without requiring a different field. Or perhaps a checkbox could automatically populate the field with the filename, and a radio button selection could set whether this is a prefix or suffix.

 

Sadly, Export As can't be scripted, so that is a dead end. There are alternative scripts to save artboards to files, however, I don't know if they are quicker or not. If they are quicker than the default artboards to files script, then they can be adapted to include prefix or suffix.

 

https://raw.githubusercontent.com/nvkzNemo/experimental-ps-scripts/master/artboardsToPSD.jsx

 

 
Another option is that a Photoshop script could batch rename the files that are output from Export As, changing the suffix to a prefix... But you would still need to enter the PSD name manually as a suffix when exporting, then run the script to rename the files.
 
EDIT:
 
The following script will copy the active document name (without extension) to the clipboard, ready to paste into the Export As Suffix field.
 
// Copy Document Name to Clipboard.jsx
#target photoshop 
var d = new ActionDescriptor();  
d.putString(stringIDToTypeID("textData"), activeDocument.name.replace(/\.[^\.]+$/, ''));  
executeAction(stringIDToTypeID("textToClipboard"), d, DialogModes.NO);
Todd_Morgan
Legend
March 31, 2023

User...

jane-e
Community Expert
Community Expert
March 31, 2023

User...

By @Todd_Morgan

 

Moved from Photoshop Developers > Ideas to Photoshop > Ideas

 

Jane

 

jane-e
Community Expert
Community Expert
March 31, 2023

@Todd_Morgan 

 

Are you a Photoshop Developer or a user with feature request?

 

Jane