Skip to main content
alex.furer
Known Participant
July 19, 2021
Answered

Rename history state by script in Photoshop

  • July 19, 2021
  • 2 replies
  • 2582 views

Already posted this over on Photoshop Family, but maybe here's the better place?

 

I have the issue that when I double click the name of a history state, it becomes editable for a split second and then I can't type a new name. I don't know where this comes from and decided to write a little script that does this for me. But the script doesn't change the name either.

 

Maybe somebody can point me in the right direction here.

 

Here's the script:

#target photoshop 

var myDoc = app.activeDocument.name;
var currentHistoryStepName = app.activeDocument.activeHistoryState;
// alert( currentHistoryStepName );
var historyStateNameOnly = currentHistoryStepName.name.replace("HistoryState ", "");
// alert( historyStateNameOnly );
var pmt = prompt ('Type a new history state name', historyStateNameOnly, 'Rename History State');
alert( pmt );
app.activeDocument.activeHistoryState.name = pmt;

 

It all works well, I get the right name as an alert but the last line does not change the history step name. Maybe someone could quickly test this on a setup where they can rename the history state name by double clicking. Then I know it's because of my base problem that renaming it this way does not work for me.

This topic has been closed for replies.
Correct answer Kukurykus

A side effect you have I'm experiencing only when I have launched ExtendScript Toolkit with targeted Photoshop. To do by scripting that you want create new document and run this code:

 

sTT = stringIDToTypeID;

(ref1 = new ActionReference()).putClass(sTT('snapshotClass'));
(dsc = new ActionDescriptor()).putReference(sTT('null'), ref1);
(ref2 = new ActionReference()).putProperty(sTT('historyState'), sTT('currentHistoryState'))
dsc.putReference(sTT('from'), ref2), dsc.putString(sTT('name'), nO = 'newOne')
dsc.putEnumerated(sTT('using'), sTT('historyState'), sTT('fullDocument'))
executeAction(sTT('make'), dsc);

(ref = new ActionReference()).putName(sTT('snapshotClass'), nO);
(dsc = new ActionDescriptor()).putReference(sTT('null'), ref), executeAction(sTT('select'), dsc);

(ref1 = new ActionReference()).putProperty(sTT('historyState'), sTT('historyBrushSource'));
(dsc = new ActionDescriptor()).putReference(sTT('null'), ref1);
(ref2 = new ActionReference()).putProperty(sTT('historyState'), sTT('currentHistoryState'))
dsc.putReference(sTT('to'), ref2), executeAction(sTT('set'), dsc)

 

2 replies

Stephen Marsh
Community Expert
Community Expert
July 19, 2021

Just in case it wasn't obvious, the alternative is to hold down opt/alt when creating the history snapshot so that it is named as you wish when you create it.

alex.furer
Known Participant
July 19, 2021

I am running this as part of an action that creates a copy of the layer, rasterizes it and then set's up the initial snapshot and I don't think I can include the alt key in the action.

 

But this is a very usefull tip for every subsequent snapshot I create.

 

Thasnk you!

 

Stephen Marsh
Community Expert
Community Expert
July 19, 2021
quote

I am running this as part of an action that creates a copy of the layer, rasterizes it and then set's up the initial snapshot and I don't think I can include the alt key in the action.

 

But this is a very usefull tip for every subsequent snapshot I create.

 

Thasnk you!

 


By @alex.furer

 

No, but if an interactive step is required, simply activate the modal control to the left of the action step. BTW I'm talking about history snapshots, not steps so I might have misunderstood. Anyway, Kukurykus has you sorted.

Kukurykus
Legend
July 19, 2021

Next time composing the post please use </> block when pasting the code 😉

Once assigned history state is unchangeable. Why did you think you can do it?

Slightly visible editable history state must be a bug? Rename history state by script

alex.furer
Known Participant
July 19, 2021

Thanks and sorry for not posting code correctly!

 

I don't really follow what you mean.

 

When in the UI you can click the snapshot button in the history panel. Once that snapshot is created, normally you can double click it's name and rename it. For some reason this doesn;t work on my setup. Same for layer names. The name becomes editable for a split second and the goes back to fixed.

 

I want to do this because I am retouching photos using the history brush and therefore I run the Camera Raw Filter, for instance, to make the sky more blue by changing the temperature globally. Then I create a snapshot of that, go one step back and gradually paint the bluer sky in using the history brush.

 

Therefore I want to name the snapshots so I can remember which snapshot does what.

 

Attached a small video showing the issue in the UI.

 

Thanks!

Kukurykus
KukurykusCorrect answer
Legend
July 19, 2021

A side effect you have I'm experiencing only when I have launched ExtendScript Toolkit with targeted Photoshop. To do by scripting that you want create new document and run this code:

 

sTT = stringIDToTypeID;

(ref1 = new ActionReference()).putClass(sTT('snapshotClass'));
(dsc = new ActionDescriptor()).putReference(sTT('null'), ref1);
(ref2 = new ActionReference()).putProperty(sTT('historyState'), sTT('currentHistoryState'))
dsc.putReference(sTT('from'), ref2), dsc.putString(sTT('name'), nO = 'newOne')
dsc.putEnumerated(sTT('using'), sTT('historyState'), sTT('fullDocument'))
executeAction(sTT('make'), dsc);

(ref = new ActionReference()).putName(sTT('snapshotClass'), nO);
(dsc = new ActionDescriptor()).putReference(sTT('null'), ref), executeAction(sTT('select'), dsc);

(ref1 = new ActionReference()).putProperty(sTT('historyState'), sTT('historyBrushSource'));
(dsc = new ActionDescriptor()).putReference(sTT('null'), ref1);
(ref2 = new ActionReference()).putProperty(sTT('historyState'), sTT('currentHistoryState'))
dsc.putReference(sTT('to'), ref2), executeAction(sTT('set'), dsc)