Creating history snapshots - code not working
I got this code from the forums here - just did some minor cleanup (using stringIDToTypeID instead of charIDToTypID which isn't as readable).
But this code doesn't execute. It runs fine up till the point where I call executeAction() - what is wrong? JSX code below!
Create
function sTID(s) { return stringIDToTypeID(s); };
function createSnapshot(name){
// Creates a history snapshot. Not possible via DOM - have to use Action Manager
alert("inside createSnapshot");
var desc = new ActionDescriptor();
var ref1 = new ActionReference();
var ref2 = new ActionReference();
ref1.putClass( sTID("Snapshot") );
desc.putReference( sTID("Null"), ref1 );
ref2.putProperty( sTID("HistoryState"), sTID("CurrentHistoryState") );
desc.putReference( sTID("From"), ref2 );
desc.putString( sTID("Name"), name );
desc.putEnumerated( sTID("Using"), sTID("HistoryStateSource"), sTID("FullDocument") );
executeAction( sTID("Make"), desc, DialogModes.NO ); // Script halts here
}
HistoryState and HistoryStateSource has a conflicting CharID "HstS" so naturally I've tested all 4 possible setups there - neither one works!
Other functions (untested):
Set
function setSnapshot(name){
// Sets the history to a previous snapshot. Not possible via DOM - have to use Action Manager
alert("inside setSnapshot");
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putName( sTID("Snapshot"), name );
desc.putReference( sTID("Null"), ref );
executeAction( sTID("Select"), desc, DialogModes.NO );
alert("reverted snapshot");
}
Delete
function removeSnapshot(name){
// Removes a history snapshot. Not possible via DOM - have to use Action Manager
alert("inside removeSnapshot");
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putName( sTID("Snapshot"), name );
desc.putReference( sTID("Null"), ref );
executeAction( sTID("Delete"), desc, DialogModes.NO );
alert("removed snapshot");
}
