: Script to automatically save a PSD when saving a PNG Can you give me a script which will save a PSD automatically when I save a PNG? I found a script that saves a PNG when saving a PSD,
Can you give me a script which will save a PSD automatically when I save a PNG?
I found a script that saves a PNG when saving a PSD, I tried to reverse it but it didn't work :(
main();
function main(){
var Name = app.activeDocument.name.replace(/.[^.]+$/, '');
var Ext = decodeURI(app.activeDocument.name).replace(/^.*./,'');
if(Ext.toLowerCase() != 'psd') return;
var Path = app.activeDocument.path;
var saveFile = File(Path + "/" + Name +".png");
if(saveFile.exists) saveFile.remove();
SavePNG(saveFile);
}
function SavePNG(saveFile){
pngSaveOptions = new PNGSaveOptions();
activeDocument.saveAs(saveFile, pngSaveOptions, true, Extension.LOWERCASE);
}
More posts by @Yeniel278
1 Comments
Sorted by latest first Latest Oldest Best
The code above doesn't have a function to save out a PSD. Your code assumes that the psd already exists.
Try this
main();
function main()
{
var Name = app.activeDocument.name.replace(/.[^.]+$/, '');
var Ext = decodeURI(app.activeDocument.name).replace(/^.*./,'');
if(Ext.toLowerCase() != 'psd') return;
// assumes the file has already been saved
var Path = app.activeDocument.path;
// Save as PSD
var SaveFile = File(Path + "/" + Name +".psd");
if(SaveFile.exists) SaveFile.remove();
SavePSD(SaveFile);
// Save as PNG
SaveFile = File(Path + "/" + Name +".png");
if(SaveFile.exists) SaveFile.remove();
SavePNG(SaveFile);
alert("File saved as .png and .psd");
}
function SavePNG(saveFile)
{
var pngSaveOptions = new PNGSaveOptions();
activeDocument.saveAs(saveFile, pngSaveOptions, true, Extension.LOWERCASE);
}
function SavePSD(saveFile)
{
var psdFile = new File(saveFile);
psdSaveOptions = new PhotoshopSaveOptions();
psdSaveOptions.embedColorProfile = true;
psdSaveOptions.alphaChannels = true;
activeDocument.saveAs(psdFile, psdSaveOptions, false, Extension.LOWERCASE);
}
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.