PhotoshopForums.com Home
Navigate Contact FAQ Search Members
Save As PNG script
Post new topic   Reply to topic    PhotoshopForums.com Forum Index -> Actions and Automation
 See a User Guidelines violation? Please contact us.
Author Message

tacchan23

Joined: 01 Jul 2014
Posts: 1



PostPosted: Tue Jul 01, 2014 1:35 am    Post subject: Save As PNG script Reply with quote

Hello,
I'd like some help with this script if possible :)
I wanted to save my open file to PNG format in the same location with the same name. I managed to do that with the scripts below.

This is a script I found on the forum:
Code:
#target photoshop
main();
function main(){
if(!documents.length) return;
try{
    var Path = decodeURI(activeDocument.path.parent);
    }catch(e){return;}
if(!Folder(Path).exists){
    alert(Path + " Does not exist!");
    return;
    }
var Name = decodeURI(app.activeDocument.name).replace(/\.[^\.]+$/, '');
var saveFile = File(Path + "/" + Name + "_bump.png");
sfwPNG24(saveFile);
//Uncomment the line below if you want to close the document.
//app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
function sfwPNG24(saveFile){
var pngOpts = new ExportOptionsSaveForWeb;
pngOpts.format = SaveDocumentType.PNG
pngOpts.PNG8 = false;
pngOpts.transparency = true;
pngOpts.interlaced = false;
pngOpts.quality = 100;
activeDocument.exportDocument(new File(saveFile),ExportType.SAVEFORWEB,pngOpts);
}


And this is how I modified it (so that it saves the file in the same folder and doesn't add any suffix to the name; also changed to save as PNG instead of using save for web):
Code:
#target photoshop
main();
function main(){
if(!documents.length) return;
try{
    var Path = decodeURI(activeDocument.path);
    }catch(e){return;}
if(!Folder(Path).exists){
    alert(Path + " Does not exist!");
    return;
    }
var Name = decodeURI(app.activeDocument.name).replace(/\.[^\.]+$/, '');
var saveFile = File(Path + "/" + Name + ".png");
sfwPNG24(saveFile);
//Uncomment the line below if you want to close the document.
//app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
function sfwPNG24(saveFile){
var pngOpts = new PNGSaveOptions;
pngOpts.compression = 9;
pngOpts.interlaced = false;
activeDocument.saveAs(saveFile, pngOpts, true, Extension.LOWERCASE);
}


My problem:
I don't know what's happening when I try to save a file just created (never saved yet). I thought I would get the Alert message but it doesn't seem to be the case (maybe the alert message in the code is related to a different condition?)
I would like to have a default folder/path in the code so that, if the file hasn't been saved yet, it would be saved in the specified location.

If anyone could do it I would really appreciate it!
Thanks :)
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    PhotoshopForums.com Forum Index -> Actions and Automation All times are GMT - 6 Hours
Page 1 of 1
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


Contact - User Guidelines >

Copyright © 2003-2016. PhotoshopForums.com, iFroggy Network. All Rights Reserved.
Powered by phpBB © phpBB Group. phpBB SEO. Privacy Policy.
We are in no way affiliated with Adobe. Photoshop, Adobe and related marks are registered trademarks of Adobe.
PhotoshopForums.com