Clear history log of script activities
Is it possible to delete all activities from the history log after the script is completed (don't delete the previous user activities)?
Thanks in advance
Is it possible to delete all activities from the history log after the script is completed (don't delete the previous user activities)?
Thanks in advance
Yes I did it the same way using their math way using the document width and height.
I wish Adobe would fix reported acknowledged bugs
It is not just resize selection I may be any transform like transforming a layer size If the is an active selection and history is suspended Adobe Scripting back up the document up a history state. Reported years ago. Photoshop: Script bug resize layer back document up one history state | Photoshop Family Customer Community
I seen script posted here the were bitten more than once they were backed up several history states.
// If you delete last line script works properly, but record the history, with last line i got errors
var startRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.CM;
var backup = app.activeDocument.historyStates.length;
var box = new Window('dialog', "INFO");
var a = ["Employee1", "Employee2", "Employee3"];
for (var i = 0; i < a.length; i += 1) {
a["_"+a] = i;
}
var c = ["001", "002", "003", "004","005", "006", "007","008", "009", "010"];
for (var i = 0; i < c.length; i += 1) {
c["_"+c] = i;
}
box.group = box.add('group', undefined );
box.group.orientation='row';
box.group.alignment = 'right';
box.group.text1 = box.group.add('statictext', undefined, "Employee");
box.group = box.group.add("dropdownlist", [25,40,160,60], a);
box.group1 = box.add('group', undefined );
box.group1.orientation='row';
box.group1.alignment = 'right';
box.group1.text1 = box.group1.add('statictext', undefined, "Iteration");
box.group1 = box.group1.add("dropdownlist", [25,40,160,60], c);
box.group5 = box.add('group', undefined );
box.group5.orientation='row';
box.group5.alignment = 'right';
box.group5.text1 = box.group5.add('statictext', undefined, "Comments");
box.group5 = box.group5.add('edittext', [25,40,160,160],"",{multiline:true, scrollable:false});
box.group8 = box.add('group', undefined );
box.group8.orientation='row';
box.group8.alignment = 'right';
box.group8.text1 = box.group8.add('statictext', undefined, "Duplicate info");
box.group8 = box.group8.add("checkbox", undefined, "Yes");
var btnGroup = box.add ("group");
btnGroup.orientation = "row";
var btnOk = btnGroup.add("button", undefined, "OK");
var btnCancel = btnGroup.add("button", undefined, "Cancel");
box.center();
btnOk.onClick = function() {
box.close(1);
};
btnCancel.onClick = function() {
box.close(0);
};
if (box.show() === 1) {
app.activeDocument.suspendHistory('INFO','main()');
}
function main(){
var GroupPsdInfo = app.activeDocument.layerSets.add();
if(box.group1.selection){
var it = box.group1.selection.text;
GroupPsdInfo.name = "INFO _" + it;}
else {
GroupPsdInfo.name = "PSD INFO";}
var infobg = app.activeDocument.artLayers.add();
var white = new SolidColor();
white.rgb["hexValue"] = "ffffff"
backgroundColor = white;
var xwidth = app.activeDocument.width.value/app.activeDocument.resolution*5.5;
var yheight = app.activeDocument.height.value/app.activeDocument.resolution*5.5;
var selectedRegion = Array(Array(0,0), Array(xwidth,0), Array(xwidth,yheight), Array(0,yheight));
app.activeDocument.selection.select(selectedRegion);
app.activeDocument.selection.fill(app.backgroundColor)
/*
app.activeDocument.selection.selectAll();
resizeSelection(5.5,5.5);
function resizeSelection(horizontal, vertical){
var strtRulerUnits = app.preferences.rulerUnits;
var strtTypeUnits = app.preferences.typeUnits;
app.preferences.rulerUnits = Units.CM;
app.preferences.typeUnits = TypeUnits.PIXELS;
var SB = activeDocument.selection.bounds;
var Height = SB[3].value - SB[1].value;
var Width = SB[2].value - SB[0].value;
var onePixH = 100/Height;
var onePixW = 100/Width;
var newWidth = onePixW * horizontal;
var newHeight = onePixH * vertical;
activeDocument.selection.resize( newWidth , newHeight, AnchorPosition.TOPLEFT);
app.preferences.rulerUnits = strtRulerUnits;
app.preferences.typeUnits = strtTypeUnits;
*/
infobg.name = "BG";
var col = new SolidColor();
col.cmyk.cyan = 0;
col.cmyk.magenta = 0;
col.cmyk.yellow = 0;
col.cmyk.black = 0;
var str = new SolidColor();
str.cmyk.cyan = 100;
str.cmyk.magenta = 30;
str.cmyk.yellow = 0;
str.cmyk.black = 0;
app.activeDocument.selection.fill(col);
app.activeDocument.selection.stroke (str,12,StrokeLocation.INSIDE, ColorBlendMode.NORMAL, 100, false);
activeDocument.selection.deselect();
infobg.move(GroupPsdInfo,ElementPlacement.INSIDE)
/*
}
*/
if(box.group5.text){
var comm = box.group5.text;
var comments = app.activeDocument.artLayers.add();
comments.kind = LayerKind.TEXT;
comments.textItem.contents = "Comments: \r" + box.group5.text.replace(/\n/g, "\r");
comments.textItem.font = "Helvetica";
comments.textItem.justification = Justification.LEFT;
comments.textItem.position = [0.5, 1.2];
comments.textItem.size = 10;
comments.move(GroupPsdInfo,ElementPlacement.INSIDE)
}
else {
var comments = app.activeDocument.artLayers.add();
comments.kind = LayerKind.TEXT;
comments.textItem.contents = "Comments: /";
comments.textItem.font = "Helvetica";
comments.textItem.justification = Justification.LEFT;
comments.textItem.position = [0.5, 1.2];
comments.textItem.size = 10;
comments.move(GroupPsdInfo,ElementPlacement.INSIDE)
}
if(box.group.selection){
var ir = box.group.selection.text;
var imageRetoucher = app.activeDocument.artLayers.add();
imageRetoucher.kind = LayerKind.TEXT;
imageRetoucher.textItem.contents = "Employee: " + ir;
imageRetoucher.textItem.font = "Helvetica";
imageRetoucher.textItem.justification = Justification.LEFT;
imageRetoucher.textItem.position = [0.5, 0.7];
imageRetoucher.textItem.size = 10;
imageRetoucher.move(GroupPsdInfo,ElementPlacement.INSIDE)
}
else {
var imageRetoucher = app.activeDocument.artLayers.add();
imageRetoucher.kind = LayerKind.TEXT;
imageRetoucher.textItem.contents = "Employee: /";
imageRetoucher.textItem.font = "Helvetica";
imageRetoucher.textItem.justification = Justification.LEFT;
imageRetoucher.textItem.position = [0.5, 0.7];
imageRetoucher.textItem.size = 10;
imageRetoucher.move(GroupPsdInfo,ElementPlacement.INSIDE)
}
var doc = app.activeDocument;
var layerParent = doc.activeLayer.parent;
if ( layerParent !== doc ) doc.activeLayer = layerParent;
if (activeDocument.activeLayer.typename === 'LayerSet') {app.activeDocument.suspendHistory('closeGroup','closeGroup(activeDocument.activeLayer)');}
function cTID(s){return charIDToTypeID(s)}
function sTID(s){return stringIDToTypeID(s)}
function openAllLayerSets( parent ){
for(var setIndex=0;setIndex<parent.layerSets.length;setIndex++){
app.activeDocument.activeLayer = parent.layerSets[setIndex].layers[0];
openAllLayerSets( parent.layerSets[setIndex]);
}
};
function closeAllLayerSets(ref) {
var layers = ref.layers;
var len = layers.length;
for ( var i = 0; i < len; i ++) {
var layer = layers;
if (layer.typename == 'LayerSet') {closeGroup(layer); var layer = layers; closeAllLayerSets(layer);};
}
}
function openGroup(layerSet) {
var m_activeLayer = activeDocument.activeLayer;
var m_Layer_Dummy01 = layerSet.artLayers.add();
var m_Layer_Dummy02 = layerSet.artLayers.add();
layerSet.layers[1].name = layerSet.layers[1].name;
m_Layer_Dummy01.remove();
m_Layer_Dummy02.remove();
activeDocument.activeLayer = m_activeLayer;
}
function closeGroup(layerSet) {
var m_Name = layerSet.name;
var m_Opacity = layerSet.opacity;
var m_BlendMode = layerSet.blendMode;
var m_LinkedLayers = layerSet.linkedLayers;
var m_bHasMask = hasLayerMask();
if(m_bHasMask) loadSelectionOfMask();
if(layerSet.layers.length <= 1) {
addLayer();
var m_Tmp = activeDocument.activeLayer;
m_Tmp.name = "dummy - feel free to remove me";
activeDocument.activeLayer = layerSet;
ungroup();
addToSelection("dummy - feel free to remove me");
groupSelected(m_Name);
} else {
activeDocument.activeLayer = layerSet;
ungroup();
groupSelected(m_Name);
}
var m_Closed = activeDocument.activeLayer;
m_Closed.opacity = m_Opacity;
m_Closed.blendMode = m_BlendMode;
for(x in m_LinkedLayers) {
if(m_LinkedLayers
.typename == "LayerSet") activeDocument.activeLayer.link(m_LinkedLayers
); }
if(m_bHasMask) maskFromSelection();
return m_Closed;
}
function ungroup() {
var m_Dsc01 = new ActionDescriptor();
var m_Ref01 = new ActionReference();
m_Ref01.putEnumerated( cTID( "Lyr " ), cTID( "Ordn" ), cTID( "Trgt" ) );
m_Dsc01.putReference( cTID( "null" ), m_Ref01 );
try {
executeAction( sTID( "ungroupLayersEvent" ), m_Dsc01, DialogModes.NO );
} catch(e) {}
}
function addLayer() {
var m_ActiveLayer = activeDocument.activeLayer;
var m_NewLayer = activeDocument.artLayers.add();
m_NewLayer.move(m_ActiveLayer, ElementPlacement.PLACEBEFORE);
return m_NewLayer;
}
function hasLayerMask() {
var m_Ref01 = new ActionReference();
m_Ref01.putEnumerated( sTID( "layer" ), cTID( "Ordn" ), cTID( "Trgt" ));
var m_Dsc01= executeActionGet( m_Ref01 );
return m_Dsc01.hasKey(cTID('Usrs'));
}
function activateLayerMask() {
var m_Dsc01 = new ActionDescriptor();
var m_Ref01 = new ActionReference();
m_Ref01.putEnumerated( cTID( "Chnl" ), cTID( "Chnl" ), cTID( "Msk " ) );
m_Dsc01.putReference( cTID( "null" ), m_Ref01 );
try {
executeAction( cTID( "slct" ), m_Dsc01, DialogModes.NO );
} catch(e) {
var m_TmpAlpha = new TemporaryAlpha();
maskFromSelection();
activateLayerMask();
m_TmpAlpha.consume();
}
}
function deleteMask(makeSelection) {
if(makeSelection) {
loadSelectionOfMask();
}
var m_Dsc01 = new ActionDescriptor();
var m_Ref01 = new ActionReference();
m_Ref01.putEnumerated( cTID( "Chnl" ), cTID( "Ordn" ), cTID( "Trgt" ) );
m_Dsc01.putReference( cTID( "null" ), m_Ref01 );
try {
executeAction( cTID( "Dlt " ), m_Dsc01, DialogModes.NO );
} catch(e) {}
}
function selectLayerMask() {
var m_Dsc01 = new ActionDescriptor();
var m_Ref01 = new ActionReference();
m_Ref01.putEnumerated(cTID("Chnl"), cTID("Chnl"), cTID("Msk "));
m_Dsc01.putReference(cTID("null"), m_Ref01);
m_Dsc01.putBoolean(cTID("MkVs"), false );
try {
executeAction(cTID("slct"), m_Dsc01, DialogModes.NO );
} catch(e) {}
}
function loadSelectionOfMask() {
selectLayerMask();
var m_Dsc01 = new ActionDescriptor();
var m_Ref01 = new ActionReference();
m_Ref01.putProperty( cTID( "Chnl" ), cTID( "fsel" ) );
m_Dsc01.putReference( cTID( "null" ), m_Ref01 );
var m_Ref02 = new ActionReference();
m_Ref02.putEnumerated( cTID( "Chnl" ), cTID( "Ordn" ), cTID( "Trgt" ) );
m_Dsc01.putReference( cTID( "T " ), m_Ref02 );
try {
executeAction( cTID( "setd" ), m_Dsc01, DialogModes.NO );
} catch(e) {}
}
function maskFromSelection() {
if(!hasLayerMask()) {
var m_Dsc01 = new ActionDescriptor();
m_Dsc01.putClass( cTID( "Nw " ), cTID( "Chnl" ) );
var m_Ref01 = new ActionReference();
m_Ref01.putEnumerated( cTID( "Chnl" ), cTID( "Chnl" ), cTID( "Msk " ) );
m_Dsc01.putReference( cTID( "At " ), m_Ref01 );
m_Dsc01.putEnumerated( cTID( "Usng" ), cTID( "UsrM" ), cTID( "RvlS" ) );
try {
executeAction( cTID( "Mk " ), m_Dsc01, DialogModes.NO );
} catch(e) {
activeDocument.selection.selectAll();
maskFromSelection();
}
} else {
if(confirm("Delete existing mask?", true, "Warning")) {
activateLayerMask();
deleteMask();
}
}
}
function groupSelected(name) {
var m_Dsc01 = new ActionDescriptor();
var m_Ref01 = new ActionReference();
m_Ref01.putClass( sTID( "layerSection" ) );
m_Dsc01.putReference( cTID( "null" ), m_Ref01 );
var m_Ref02 = new ActionReference();
m_Ref02.putEnumerated( cTID( "Lyr " ), cTID( "Ordn" ), cTID( "Trgt" ) );
m_Dsc01.putReference( cTID( "From" ), m_Ref02 );
var m_Dsc02 = new ActionDescriptor();
m_Dsc02.putString( cTID( "Nm " ), name);
m_Dsc01.putObject( cTID( "Usng" ), sTID( "layerSection" ), m_Dsc02 );
executeAction( cTID( "Mk " ), m_Dsc01, DialogModes.NO );
return activeDocument.activeLayer;
}
function addToSelection(layerName) {
var m_Dsc01 = new ActionDescriptor();
var m_Ref01 = new ActionReference();
m_Ref01.putName( cTID( "Lyr " ), layerName );
m_Dsc01.putReference( cTID( "null" ), m_Ref01 );
m_Dsc01.putEnumerated( sTID( "selectionModifier" ), sTID( "selectionModifierType" ), sTID( "addToSelection" ) );
m_Dsc01.putBoolean( cTID( "MkVs" ), false );
try {
executeAction( cTID( "slct" ), m_Dsc01, DialogModes.NO );
} catch(e) {}
}
function TemporaryAlpha() {
activeDocument.selection.store((this.alpha = activeDocument.channels.add()));
activeDocument.selection.deselect();
this.consume = function() {
activeDocument.selection.load(this.alpha);
this.alpha.remove();
}
}
layerColour("yellow");
function layerColour(colour) {
switch (colour.toLocaleLowerCase()){
case 'red': colour = 'Rd '; break;
case 'orange' : colour = 'Orng'; break;
case 'yellow' : colour = 'Ylw '; break;
case 'yellow' : colour = 'Ylw '; break;
case 'green' : colour = 'Grn '; break;
case 'blue' : colour = 'Bl '; break;
case 'violet' : colour = 'Vlt '; break;
case 'gray' : colour = 'Gry '; break;
case 'none' : colour = 'None'; break;
default : colour = 'None'; break;
}
var desc = new ActionDescriptor();
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
desc.putReference( charIDToTypeID('null'), ref );
var desc2 = new ActionDescriptor();
desc2.putEnumerated( charIDToTypeID('Clr '), charIDToTypeID('Clr '), charIDToTypeID(colour) );
desc.putObject( charIDToTypeID('T '), charIDToTypeID('Lyr '), desc2 );
executeAction( charIDToTypeID('setd'), desc, DialogModes.NO );
};
if(box.group8.value){
if( app.documents.length > 0 ){
duplicateToAll();
}
function duplicateToAll(){
docs = app.documents;
curDoc = app.activeDocument;
for(var i = 0; i < docs.length; i++){
if(curDoc != docs){
var curLayer;
try { curLayer = docs.activeLayer; } catch(e) {}
curDoc.activeLayer.duplicate(docs,ElementPlacement.PLACEATBEGINNING);
}
app.activeDocument = curDoc;
}
}
function cTID(s){return charIDToTypeID(s)}
function sTID(s){return stringIDToTypeID(s)}
}
}
box.close();
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.