Highlighted

Maybe an Array?

Community Beginner ,
Oct 14, 2020

Copy link to clipboard

Copied

I've put together this code. I know it's not the most effiecient way of doing this. I assume an array is the proper way? But I dont know how to do them or how to get them to work. 

 

PSDsave();
TIFsave();
saveActDocJPG();

function saveActDocJPG() {
var docLength = app.documents.length;
for ( var i = 0; i < docLength; i++ ) {
var doc = app.activeDocument;
// doc.save();

////// change path below ///////////
var docPath = '/Volumes/CT-WORK/Prep Work/';
var folderString = docPath + "/" + "JPG";
if ( Folder( folderString ).exists == false ) {
new Folder( folderString ).create()
}
// var docName = doc.name.split( '.' )[ 0 ];
// var docName = doc.name.match( /(.*)\.[^\.]+$/ )[ 1 ]

var docName = doc.name.replace( /\.[^\.]+$/, '' );
var jpgOptions = new JPEGSaveOptions();
jpgOptions.quality = 8;
jpgOptions.embedColorProfile = true;
doc.saveAs( new File( folderString + "/" + docName + '.jpg' ), jpgOptions, true );
// doc.close( SaveOptions.DONOTSAVECHANGES );
doc.close( SaveOptions.SAVECHANGES );
}
alert( "JPG-8" + "\n\n" + "You Saved " + docLength + " Open Files." );
}


function PSDsave() {

var docLength = app.documents.length;
for ( var i = 0; i < docLength; i++ ) {
var doc = app.activeDocument;
// doc.save();

////// change path below ///////////
var docPath = '/Volumes/CT-WORK/Prep Work/';
var folderString = docPath + "/" + "PSD";
if ( Folder( folderString ).exists == false ) {
new Folder( folderString ).create()
}
// var docName = doc.name.split( '.' )[ 0 ];
// var docName = doc.name.match( /(.*)\.[^\.]+$/ )[ 1 ]

// psd options;
var docName = doc.name.replace( /\.[^\.]+$/, '' );
psdOpts = new PhotoshopSaveOptions();
psdOpts.embedColorProfile = true;
psdOpts.alphaChannels = true;
// change this to true if you want all the layers in the copy;
psdOpts.layers = true;
psdOpts.spotColors = true;
doc.saveAs( ( new File( folderString + "/" + docName + ".psd" ) ), psdOpts, true );
// doc.close( SaveOptions.DONOTSAVECHANGES );
// doc.close( SaveOptions.SAVECHANGES );
}
alert( "PSD" + "\n\n" + "You Saved " + docLength + " Open Files." );
}


function TIFsave() {

var docLength = app.documents.length;
for ( var i = 0; i < docLength; i++ ) {
var doc = app.activeDocument;
// doc.save();

////// change path below ///////////
var docPath = '/Volumes/CT-WORK/Prep Work/';
var folderString = docPath + "/" + "TIF";
if ( Folder( folderString ).exists == false ) {
new Folder( folderString ).create()
}
// var docName = doc.name.split( '.' )[ 0 ];
// var docName = doc.name.match( /(.*)\.[^\.]+$/ )[ 1 ]

// psd options;
var docName = doc.name.replace( /\.[^\.]+$/, '' );
TiffOpts = new TiffSaveOptions();
TiffOpts.embedColorProfile = true;
TiffOpts.alphaChannels = false;
// change this to true if you want all the layers in the copy;
TiffOpts.layers = false;
TiffOpts.spotColors = true;
doc.saveAs( ( new File( folderString + "/" + docName + ".tif" ) ), TiffOpts, true );
// doc.close( SaveOptions.DONOTSAVECHANGES );
// doc.close( SaveOptions.SAVECHANGES );
}
alert( "TIF" + "\n\n" + "You Saved " + docLength + " Open Files." );

}

Adobe Community Professional
Correct answer by Manan Joshi | Adobe Community Professional

You could save the different formats in a single method, something like the following

function saveActDoc() {
	var docLength = app.documents.length;
	for ( var i = 0; i < docLength; i++ ) {
		var doc = app.activeDocument;
		// doc.save();

		////// change path below ///////////
		var docPath = '/Volumes/CT-WORK/Prep Work/';
		var folderString = docPath + "/" + "JPG";
		if ( Folder( folderString ).exists == false ) {
			new Folder( folderString ).create()
		}
		// var docName = doc.name.split( '.' )[ 0 ];
		// var docName = doc.name.match( /(.*)\.[^\.]+$/ )[ 1 ]

		var docName = doc.name.replace( /\.[^\.]+$/, '' );
		var jpgOptions = new JPEGSaveOptions();
		jpgOptions.quality = 8;
		jpgOptions.embedColorProfile = true;
		doc.saveAs( new File( folderString + "/" + docName + '.jpg' ), jpgOptions, true );
		// doc.close( SaveOptions.DONOTSAVECHANGES );
		
		var psdOpts = new PhotoshopSaveOptions();
		psdOpts.embedColorProfile = true;
		psdOpts.alphaChannels = true;
		// change this to true if you want all the layers in the copy;
		psdOpts.layers = true;
		psdOpts.spotColors = true;
		doc.saveAs( ( new File( folderString + "/" + docName + ".psd" ) ), psdOpts, true );
		
		
		var TiffOpts = new TiffSaveOptions();
		TiffOpts.embedColorProfile = true;
		TiffOpts.alphaChannels = false;
		// change this to true if you want all the layers in the copy;
		TiffOpts.layers = false;
		TiffOpts.spotColors = true;
		doc.saveAs( ( new File( folderString + "/" + docName + ".tif" ) ), TiffOpts, true );

		doc.close( SaveOptions.SAVECHANGES );
	}
	alert( "JPG-8" + "\n\n" + "You Saved " + docLength + " Open Files." );
}

-Manan

TOPICS
How to, Mac, Problem or error, Windows

Views

70

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Maybe an Array?

Community Beginner ,
Oct 14, 2020

Copy link to clipboard

Copied

I've put together this code. I know it's not the most effiecient way of doing this. I assume an array is the proper way? But I dont know how to do them or how to get them to work. 

 

PSDsave();
TIFsave();
saveActDocJPG();

function saveActDocJPG() {
var docLength = app.documents.length;
for ( var i = 0; i < docLength; i++ ) {
var doc = app.activeDocument;
// doc.save();

////// change path below ///////////
var docPath = '/Volumes/CT-WORK/Prep Work/';
var folderString = docPath + "/" + "JPG";
if ( Folder( folderString ).exists == false ) {
new Folder( folderString ).create()
}
// var docName = doc.name.split( '.' )[ 0 ];
// var docName = doc.name.match( /(.*)\.[^\.]+$/ )[ 1 ]

var docName = doc.name.replace( /\.[^\.]+$/, '' );
var jpgOptions = new JPEGSaveOptions();
jpgOptions.quality = 8;
jpgOptions.embedColorProfile = true;
doc.saveAs( new File( folderString + "/" + docName + '.jpg' ), jpgOptions, true );
// doc.close( SaveOptions.DONOTSAVECHANGES );
doc.close( SaveOptions.SAVECHANGES );
}
alert( "JPG-8" + "\n\n" + "You Saved " + docLength + " Open Files." );
}


function PSDsave() {

var docLength = app.documents.length;
for ( var i = 0; i < docLength; i++ ) {
var doc = app.activeDocument;
// doc.save();

////// change path below ///////////
var docPath = '/Volumes/CT-WORK/Prep Work/';
var folderString = docPath + "/" + "PSD";
if ( Folder( folderString ).exists == false ) {
new Folder( folderString ).create()
}
// var docName = doc.name.split( '.' )[ 0 ];
// var docName = doc.name.match( /(.*)\.[^\.]+$/ )[ 1 ]

// psd options;
var docName = doc.name.replace( /\.[^\.]+$/, '' );
psdOpts = new PhotoshopSaveOptions();
psdOpts.embedColorProfile = true;
psdOpts.alphaChannels = true;
// change this to true if you want all the layers in the copy;
psdOpts.layers = true;
psdOpts.spotColors = true;
doc.saveAs( ( new File( folderString + "/" + docName + ".psd" ) ), psdOpts, true );
// doc.close( SaveOptions.DONOTSAVECHANGES );
// doc.close( SaveOptions.SAVECHANGES );
}
alert( "PSD" + "\n\n" + "You Saved " + docLength + " Open Files." );
}


function TIFsave() {

var docLength = app.documents.length;
for ( var i = 0; i < docLength; i++ ) {
var doc = app.activeDocument;
// doc.save();

////// change path below ///////////
var docPath = '/Volumes/CT-WORK/Prep Work/';
var folderString = docPath + "/" + "TIF";
if ( Folder( folderString ).exists == false ) {
new Folder( folderString ).create()
}
// var docName = doc.name.split( '.' )[ 0 ];
// var docName = doc.name.match( /(.*)\.[^\.]+$/ )[ 1 ]

// psd options;
var docName = doc.name.replace( /\.[^\.]+$/, '' );
TiffOpts = new TiffSaveOptions();
TiffOpts.embedColorProfile = true;
TiffOpts.alphaChannels = false;
// change this to true if you want all the layers in the copy;
TiffOpts.layers = false;
TiffOpts.spotColors = true;
doc.saveAs( ( new File( folderString + "/" + docName + ".tif" ) ), TiffOpts, true );
// doc.close( SaveOptions.DONOTSAVECHANGES );
// doc.close( SaveOptions.SAVECHANGES );
}
alert( "TIF" + "\n\n" + "You Saved " + docLength + " Open Files." );

}

Adobe Community Professional
Correct answer by Manan Joshi | Adobe Community Professional

You could save the different formats in a single method, something like the following

function saveActDoc() {
	var docLength = app.documents.length;
	for ( var i = 0; i < docLength; i++ ) {
		var doc = app.activeDocument;
		// doc.save();

		////// change path below ///////////
		var docPath = '/Volumes/CT-WORK/Prep Work/';
		var folderString = docPath + "/" + "JPG";
		if ( Folder( folderString ).exists == false ) {
			new Folder( folderString ).create()
		}
		// var docName = doc.name.split( '.' )[ 0 ];
		// var docName = doc.name.match( /(.*)\.[^\.]+$/ )[ 1 ]

		var docName = doc.name.replace( /\.[^\.]+$/, '' );
		var jpgOptions = new JPEGSaveOptions();
		jpgOptions.quality = 8;
		jpgOptions.embedColorProfile = true;
		doc.saveAs( new File( folderString + "/" + docName + '.jpg' ), jpgOptions, true );
		// doc.close( SaveOptions.DONOTSAVECHANGES );
		
		var psdOpts = new PhotoshopSaveOptions();
		psdOpts.embedColorProfile = true;
		psdOpts.alphaChannels = true;
		// change this to true if you want all the layers in the copy;
		psdOpts.layers = true;
		psdOpts.spotColors = true;
		doc.saveAs( ( new File( folderString + "/" + docName + ".psd" ) ), psdOpts, true );
		
		
		var TiffOpts = new TiffSaveOptions();
		TiffOpts.embedColorProfile = true;
		TiffOpts.alphaChannels = false;
		// change this to true if you want all the layers in the copy;
		TiffOpts.layers = false;
		TiffOpts.spotColors = true;
		doc.saveAs( ( new File( folderString + "/" + docName + ".tif" ) ), TiffOpts, true );

		doc.close( SaveOptions.SAVECHANGES );
	}
	alert( "JPG-8" + "\n\n" + "You Saved " + docLength + " Open Files." );
}

-Manan

TOPICS
How to, Mac, Problem or error, Windows

Views

71

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Oct 14, 2020 0
Adobe Community Professional ,
Oct 14, 2020

Copy link to clipboard

Copied

You could save the different formats in a single method, something like the following

function saveActDoc() {
	var docLength = app.documents.length;
	for ( var i = 0; i < docLength; i++ ) {
		var doc = app.activeDocument;
		// doc.save();

		////// change path below ///////////
		var docPath = '/Volumes/CT-WORK/Prep Work/';
		var folderString = docPath + "/" + "JPG";
		if ( Folder( folderString ).exists == false ) {
			new Folder( folderString ).create()
		}
		// var docName = doc.name.split( '.' )[ 0 ];
		// var docName = doc.name.match( /(.*)\.[^\.]+$/ )[ 1 ]

		var docName = doc.name.replace( /\.[^\.]+$/, '' );
		var jpgOptions = new JPEGSaveOptions();
		jpgOptions.quality = 8;
		jpgOptions.embedColorProfile = true;
		doc.saveAs( new File( folderString + "/" + docName + '.jpg' ), jpgOptions, true );
		// doc.close( SaveOptions.DONOTSAVECHANGES );
		
		var psdOpts = new PhotoshopSaveOptions();
		psdOpts.embedColorProfile = true;
		psdOpts.alphaChannels = true;
		// change this to true if you want all the layers in the copy;
		psdOpts.layers = true;
		psdOpts.spotColors = true;
		doc.saveAs( ( new File( folderString + "/" + docName + ".psd" ) ), psdOpts, true );
		
		
		var TiffOpts = new TiffSaveOptions();
		TiffOpts.embedColorProfile = true;
		TiffOpts.alphaChannels = false;
		// change this to true if you want all the layers in the copy;
		TiffOpts.layers = false;
		TiffOpts.spotColors = true;
		doc.saveAs( ( new File( folderString + "/" + docName + ".tif" ) ), TiffOpts, true );

		doc.close( SaveOptions.SAVECHANGES );
	}
	alert( "JPG-8" + "\n\n" + "You Saved " + docLength + " Open Files." );
}

-Manan

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 14, 2020 1
Community Beginner ,
Oct 14, 2020

Copy link to clipboard

Copied

Thank you, this also works. I had to modify it a bit to ensure each extension file saves in it's own folder. . I don't think we can control how fast the files save. lol. I was trying to shave some time of the saveing time. But, Photoshop, am i right? lol.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 14, 2020 0
Adobe Community Professional ,
Oct 14, 2020

Copy link to clipboard

Copied

No, once the API call is made for export or for that matter any other API the time taken mostly depends upon things like how big is the document etc. Now related to saving time, in your code always look for things that are repeated and can be removed, like you were calling multiple methods and running a loop on the document collection in each one of them when it could be done in a single method. You need to balance between code readability, code structure while avoiding code redundancy

-Manan

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 14, 2020 1