Copy link to clipboard
Copied
Hello everyone!
I managed to frankenstein together a javascript I found online to save out a JPG and PNG from a PSD to the parent directory and folder inside the parent directory. After a couple of nights of troubleshooting, the script below is doing MOSTLY what I need. From the working file (the PSD directory), I'm able to save out a JPG to the parent directory but I can't figure out the magic combination to send the PNG to the PARENT->PNG folder. Any help is appreciated!
MY DIRECTORY + FILE SETUP:
THE SCRIPT:
// reference open doc
var doc = app.activeDocument;
// define parent directory
var parentF = new Folder(doc.path.parent);
// set save options for JPG
var jpg = new ExportOptionsSaveForWeb();
jpg.interlaced = false;
jpg.quality = 100;
jpg.includeProfile = false;
jpg.format = SaveDocumentType.JPEG; // Document Type
// save png file in parent directory of open doc
activeDocument.exportDocument((doc.path.parent), ExportType.SAVEFORWEB, jpg);
//set save options for PNG
var png = new ExportOptionsSaveForWeb();
png.PNG8 = false;
png.transparency = true;
png.interlaced = false;
png.quality = 100;
png.includeProfile = false;
png.format = SaveDocumentType.PNG; // Document Type
// save png file in PNG folder in parent directory
activeDocument.exportDocument((doc.path.parent + '/PNG'), ExportType.SAVEFORWEB, png);
Document.exportDocument (exportIn: File , exportAs: ExportType , options: ExportOptions )
First argument must be File (full path with filename). Folder to export this file must be created before.
var png = new ExportOptionsSaveForWeb();
png.PNG8 = false;
png.transparency = true;
png.interlaced = false;
png.quality = 100;
png.includeProfile = false;
png.format = SaveDocumentType.PNG;
// save png file in PNG folder in parent directory
var exportFolder = Folder ((app.activeDocument.path.parent
...
Copy link to clipboard
Copied
Document.exportDocument (exportIn: File , exportAs: ExportType , options: ExportOptions )
First argument must be File (full path with filename). Folder to export this file must be created before.
var png = new ExportOptionsSaveForWeb();
png.PNG8 = false;
png.transparency = true;
png.interlaced = false;
png.quality = 100;
png.includeProfile = false;
png.format = SaveDocumentType.PNG;
// save png file in PNG folder in parent directory
var exportFolder = Folder ((app.activeDocument.path.parent) + "/PNG")
if (!exportFolder.exists) exportFolder.create ()
app.activeDocument.exportDocument (File(exportFolder + "/" + app.activeDocument.name + ".png"),ExportType.SAVEFORWEB, png )
Copy link to clipboard
Copied
This is perfect! Thank you very much, Dmitry!
Copy link to clipboard
Copied
Hi Dmitry I like your script, however, one thing struck me as potentially requiring modification...
I'd add a filename variable to strip the source filename extension so that the result is not a double extension such as .psd.png etc.
var baseName = app.activeDocument.name.split('.')[0];
//...
app.activeDocument.exportDocument (File(exportFolder + "/" + baseName + ".png"),ExportType.SAVEFORWEB, png )
Copy link to clipboard
Copied
Great catch, Stephen. I noticed one of the files had the psd.png and your update corrected it. Thanks so much!
Copy link to clipboard
Copied
download and install the plug-in Image Processor Pro.... It should be easy to do what you want to do using it.
Copy link to clipboard
Copied
Ah nice. I'll look into it. Thanks JJ!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now