Skip to content

Instantly share code, notes, and snippets.

@borkweb
Last active February 27, 2021 18:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save borkweb/8099778 to your computer and use it in GitHub Desktop.
Save borkweb/8099778 to your computer and use it in GitHub Desktop.
Photoshop Script for saving lightsaber mutations with Actions
/**
* Save lightsaber mutations to different files
* Created by: Matthew Batchelder (Orv Dessrx)
* For: Dark Jedi Brotherhood https://www.darkjedibrotherhood.com
*/
if ( 0 !== app.documents.length ) {
var doc = app.documents[0];
var filename = doc.name.substring( 0, doc.name.indexOf( '.' ) );
var file;
var options;
var trim;
var color;
var history;
var trims = [
'consular',
'guardian',
'krath',
'obelisk',
'sentinel',
'sith',
'standard'
];
var colors = [
'blue',
'green',
'lightblue',
'red',
'purple',
'yellow'
];
options = new ExportOptionsSaveForWeb();
options.format = SaveDocumentType.PNG;
options.PNG8 = false;
options.quality = 100;
for ( var i = 0; i < trims.length; i++ ) {
trim = trims[ i ];
for ( var j = 0; j < colors.length; j++ ) {
color = colors[ j ];
// execute the action that matches "[trim] [color]" in the "saber colors" action group
app.doAction( trim + ' ' + color, 'saber colors' );
// merge layers to preserve gradients and shizzle
doc.flatten();
// resize the image
doc.resizeImage( null, UnitValue( 400, 'px' ), null, ResampleMethod.BICUBIC );
// export the file
file = new File( doc.path + '/' + filename + '-' + trim + '-' + color + '.png' );
doc.exportDocument( file, ExportType.SAVEFORWEB, options );
// reset the history
doc.activeHistoryState = doc.historyStates[ doc.historyStates.length - 3 ];
// purge undone history
app.purge( PurgeTarget.HISTORYCACHES );
}//end for
}//end for
}//end if
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment