Skip to content

Commit

Permalink
feat: allow batch operation (antipalindrome#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
antipalindrome committed Jan 28, 2022
1 parent 607d516 commit a759897
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 29 deletions.
58 changes: 30 additions & 28 deletions Export Layers To Files (Fast).jsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
// NAME:
// Export Layers To Files

// DESCRIPTION:
// Improved version of the built-in "Export Layers To Files" script:
// * Supports PNG and possibly other formats in the future.
// * Does not create multiple document duplicates, so it's much faster.
// Saves each layer in the active document to a file in a preferred format named after the layer. Supported formats:
// * PNG
// * JPEG
// * Targa
// * BMP
// VERSION:
// v2.6.0

// REQUIRES:
// Adobe Photoshop CS2 or higher

// Most current version always available at: https://github.com/hsw107/Photoshop-Export-Layers-to-Files-Fast
// Most current version always available at: https://github.com/antipalindrome/Photoshop-Export-Layers-to-Files-Fast

// enable double-clicking from Finder/Explorer (CS2 and higher)
#target photoshop

var BATCH_OPERATION = false;

app.bringToFront();

//
Expand Down Expand Up @@ -470,7 +465,10 @@ function main() {
}

// show dialog
if (showDialog() === 1) {
if (BATCH_OPERATION || showDialog() === 1) {
if(BATCH_OPERATION) {
finalizeSettingsPrerun();
}
prefs.documentName = app.activeDocument.name.split('.')[0];
env.documentCopy = app.activeDocument.duplicate();

Expand Down Expand Up @@ -521,7 +519,7 @@ function main() {
if (count.error) {
message += "\n\nSome layers failed to export! (Are there many layers with the same name?)";
}
if(!prefs.silent) {
if(!prefs.silent && !BATCH_OPERATION) {
alert(message, "Finished", count.error);
}
}
Expand Down Expand Up @@ -1090,6 +1088,23 @@ function isAdjustmentLayer(layer) {

}

function finalizeSettingsPrerun() {
// Reload prefs to make sure they are up-to-date
prefs = getSettings();

// Some image format prefs are not retained through inputs
// so we need to load them separately
var format = Formats[prefs.fileType];
prefs.fileType = format.fileType;
prefs.fileExtension = format.fileExtension;
prefs.formatArgs = format.formatArgs();

var destFolder = new Folder(prefs.destination);
if (!destFolder.exists) {
destFolder.create();
}
}

//
// User interface
//
Expand Down Expand Up @@ -1247,23 +1262,10 @@ function showDialog() {
// ==============
fields.btnRun.onClick = function() {
saveSettings(dialog);

// Reload prefs to make sure they are up-to-date
prefs = getSettings();

// Some image format prefs are not retained through inputs
// so we need to load them separately
finalizeSettingsPrerun();

var format = Formats[prefs.fileType];
fields.tabpnlExportOptions.selection = format.index;
prefs.fileType = format.fileType;
prefs.fileExtension = format.fileExtension;
prefs.formatArgs = format.formatArgs();

var destFolder = new Folder(prefs.destination);
if (!destFolder.exists) {
destFolder.create();
}


dialog.close(1);
};
Expand Down Expand Up @@ -2566,7 +2568,7 @@ function makeMainDialog() {
// DIALOG
// ======
var dialog = new Window("dialog", undefined, undefined, {closeButton: false, resizeable: true});
dialog.text = "Export Layers To Files v2.5.0";
dialog.text = "Export Layers To Files v2.6.0";
dialog.orientation = "column";
dialog.alignChildren = ["center","center"];
dialog.spacing = 5;
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,21 @@ Prefix and Suffix fields can take the following string substitutes.

- Currently we do not support multiple artboards for export

## Batch Processing / Actions

Many people like to set up the script once, and then use batch processing or actions to automatically run the script.

To use the script this way, follow these instructions:

1. Run the script, set your desired settings in the dialog and then hit "Save and Close"
2. Open up the script file, in TextEdit (Mac), Notepad (Windows), or in a code IDE.
3. At the top of the script, locate the code that reads `var BATCH_OPERATION = false;`
4. Change this to say `var BATCH_OPERATION = true;`
5. You can now rerun the script, and it will auto-run with the previous settings.

In order to make changes to the settings again, you'll need to change `BATCH_OPERATION` back to `false` and rerun the script.


## Requirements

We do our best to have the script be backwards compatible (back to Adobe Photoshop CS2) but are limited in what we can test for, both by Photoshop versions as well as OS. If you are encountering any issues with the current version, try downloading [previous versions](https://github.com/antipalindrome/Photoshop-Export-Layers-to-Files-Fast/releases) of the script instead.
Expand Down
2 changes: 1 addition & 1 deletion dev/dialog.js

Large diffs are not rendered by default.

0 comments on commit a759897

Please sign in to comment.