Mobile app version of vmapp.org
Login or Join
Yeniel278

: 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,

@Yeniel278

Posted in: #AdobePhotoshop #Export #PhotoshopScripting

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);
}

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Yeniel278

1 Comments

Sorted by latest first Latest Oldest Best

 

@Ogunnowo857

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);
}

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme