Skip to main content
Bojan Živković11378569
Community Expert
Community Expert
April 19, 2024
Answered

Script to export snapshots as JPEG with the snapshot names?

  • April 19, 2024
  • 1 reply
  • 371 views

Is there any script to save time by exporting all saved snapshots as separate files using snapshot names?

This topic has been closed for replies.
Correct answer Stephen Marsh

Ah, yeah, it's that old problem with the forum software changeover where variables in square brackets were lost.

 

Try this, full credit to @SuperMerlin:

 

 

/* https://community.adobe.com/t5/photoshop-ecosystem-discussions/save-all-history-snapshots-as-files/m-p/7857534 */
#target photoshop;  
app.bringToFront();  
main();  
function main(){  
if(!documents.length) return;  
try{  
    var Path = activeDocument.path;  
    }catch(err){  
        alert("You save your document before running this script!");  
        return;  
        }  
var doc = app.activeDocument;  
var now = doc.activeHistoryState;  
var Snaps = snapShotList();  
var outputFolder = Folder(Path + "/snapshots");  
if(!outputFolder.exists) outputFolder.create();  
for (var z in Snaps){  
    revertNamedSnapshot(Snaps[z]);  
    var saveFile = File(outputFolder + "/" + Snaps[z].toString().replace(/\./g,'_') + ".jpg");  
    //var saveFile = File(outputFolder + "/" + Snaps[z].toString().replace(/\./g,'_') + ".psd");  
    //var saveFile = File(outputFolder + "/" + Snaps[z].toString().replace(/\./g,'_') + ".tif");  
  
    SaveForWeb(saveFile,80);  
    //SavePSD(saveFile);  
    //SaveTIFF(saveFile);  
    }  
doc.activeHistoryState = now;  
};  
function SaveTIFF(saveFile){  
tiffSaveOptions = new TiffSaveOptions();   
tiffSaveOptions.embedColorProfile = true;  
tiffSaveOptions.byteOrder = ByteOrder.IBM;  
tiffSaveOptions.transparency=true;  
tiffSaveOptions.interleaveChannels=true;  
tiffSaveOptions.alphaChannels = false;   
tiffSaveOptions.imageCompression = TIFFEncoding.NONE;   
activeDocument.saveAs(saveFile, tiffSaveOptions, true, Extension.LOWERCASE);   
};  
function SavePSD(saveFile){   
psdSaveOptions = new PhotoshopSaveOptions();   
psdSaveOptions.embedColorProfile = true;   
psdSaveOptions.alphaChannels = true;    
psdSaveOptions.layers = true;
psdSaveOptions.annotations = true;
psdSaveOptions.spotColors = true;
activeDocument.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE);   
};  
function SaveForWeb(saveFile,jpegQuality) {  
var sfwOptions = new ExportOptionsSaveForWeb();   
   sfwOptions.format = SaveDocumentType.JPEG;   
   sfwOptions.includeProfile = false;   
   sfwOptions.interlaced = 0;   
   sfwOptions.optimized = true;   
   sfwOptions.quality = jpegQuality;  
activeDocument.exportDocument(saveFile, ExportType.SAVEFORWEB, sfwOptions);  
};  
function snapShotList(){  
var doc = app.activeDocument;  
var hs = doc.historyStates;  
var now = doc.activeHistoryState;  
var Name = new Array();  
for(var a =0;a <hs.length;a++){  
   if(hs[a].snapshot) {  
       doc.activeHistoryState = hs[a];  
       Name.push(hs[a].name);  
       }  
    }  
doc.activeHistoryState = now;  
return Name;  
};  
function revertNamedSnapshot(name) {  
var desc = new ActionDescriptor();  
var ref = new ActionReference();  
ref.putName( charIDToTypeID('SnpS'), name );  
desc.putReference( charIDToTypeID('null'), ref );  
executeAction( charIDToTypeID('slct'), desc, DialogModes.NO );  
};  

 

1 reply

Stephen Marsh
Community Expert
Community Expert
April 19, 2024
Bojan Živković11378569
Community Expert
Community Expert
April 19, 2024

No success in the initial few attempts.

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
April 19, 2024

Ah, yeah, it's that old problem with the forum software changeover where variables in square brackets were lost.

 

Try this, full credit to @SuperMerlin:

 

 

/* https://community.adobe.com/t5/photoshop-ecosystem-discussions/save-all-history-snapshots-as-files/m-p/7857534 */
#target photoshop;  
app.bringToFront();  
main();  
function main(){  
if(!documents.length) return;  
try{  
    var Path = activeDocument.path;  
    }catch(err){  
        alert("You save your document before running this script!");  
        return;  
        }  
var doc = app.activeDocument;  
var now = doc.activeHistoryState;  
var Snaps = snapShotList();  
var outputFolder = Folder(Path + "/snapshots");  
if(!outputFolder.exists) outputFolder.create();  
for (var z in Snaps){  
    revertNamedSnapshot(Snaps[z]);  
    var saveFile = File(outputFolder + "/" + Snaps[z].toString().replace(/\./g,'_') + ".jpg");  
    //var saveFile = File(outputFolder + "/" + Snaps[z].toString().replace(/\./g,'_') + ".psd");  
    //var saveFile = File(outputFolder + "/" + Snaps[z].toString().replace(/\./g,'_') + ".tif");  
  
    SaveForWeb(saveFile,80);  
    //SavePSD(saveFile);  
    //SaveTIFF(saveFile);  
    }  
doc.activeHistoryState = now;  
};  
function SaveTIFF(saveFile){  
tiffSaveOptions = new TiffSaveOptions();   
tiffSaveOptions.embedColorProfile = true;  
tiffSaveOptions.byteOrder = ByteOrder.IBM;  
tiffSaveOptions.transparency=true;  
tiffSaveOptions.interleaveChannels=true;  
tiffSaveOptions.alphaChannels = false;   
tiffSaveOptions.imageCompression = TIFFEncoding.NONE;   
activeDocument.saveAs(saveFile, tiffSaveOptions, true, Extension.LOWERCASE);   
};  
function SavePSD(saveFile){   
psdSaveOptions = new PhotoshopSaveOptions();   
psdSaveOptions.embedColorProfile = true;   
psdSaveOptions.alphaChannels = true;    
psdSaveOptions.layers = true;
psdSaveOptions.annotations = true;
psdSaveOptions.spotColors = true;
activeDocument.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE);   
};  
function SaveForWeb(saveFile,jpegQuality) {  
var sfwOptions = new ExportOptionsSaveForWeb();   
   sfwOptions.format = SaveDocumentType.JPEG;   
   sfwOptions.includeProfile = false;   
   sfwOptions.interlaced = 0;   
   sfwOptions.optimized = true;   
   sfwOptions.quality = jpegQuality;  
activeDocument.exportDocument(saveFile, ExportType.SAVEFORWEB, sfwOptions);  
};  
function snapShotList(){  
var doc = app.activeDocument;  
var hs = doc.historyStates;  
var now = doc.activeHistoryState;  
var Name = new Array();  
for(var a =0;a <hs.length;a++){  
   if(hs[a].snapshot) {  
       doc.activeHistoryState = hs[a];  
       Name.push(hs[a].name);  
       }  
    }  
doc.activeHistoryState = now;  
return Name;  
};  
function revertNamedSnapshot(name) {  
var desc = new ActionDescriptor();  
var ref = new ActionReference();  
ref.putName( charIDToTypeID('SnpS'), name );  
desc.putReference( charIDToTypeID('null'), ref );  
executeAction( charIDToTypeID('slct'), desc, DialogModes.NO );  
};