I find it impossible to follow what you have written here. You show three sections of a script so we can not test or see what the script actually does and you show a couple of history states. State it does not work if multiple layers are selected.
What does not work? I know there is a bug in supendHistory that a script can trigger the will backup history and cause problems. Can not tell if you code triggers the bug though. The bug I reported is in ever version of Photoshop I have installed. There is one thread in this forum where someone was having a problem with a script and could not find the problem. Their script triggered the bug to bite three times.
Currently I have CS2, CS6, CC, CC 2014, CC 2015, CC 2015.5 and CC 2017 installed. The supendHistory bug is in all of them. Adobe does not fix all acknowledged bugs. If what you are seeing is this bug or an other bug in Adobe scripting you may need to code around it. Photoshop: Script bug resize layer back document up one history state | Photoshop Family Customer Community
Sorry, it is only about what is displayed in the history.
The code should show only the steps.
A group is created and contains two layers.
At the end, the group should be selected.
With suspendHistory, everything should be displayed as just one step.
But selecting the group is a separate step.
I would like to do everything as a single step and asked if that is possible
If you post the script and describe how to use it. We could create the type of document needed then target several layers and see if we see the same problem as you in the version of Photoshop we use. What version of Photoshop do you use and what OS do you use? I have seen only one step recorded when the first thing a does is suspend history an names the current state. I also do not recognize the history state "Layer Changes"" as a Photoshop step. What state does you document back up to when you activate that history state? What event recorded that history state.
I found the MY mistake.
I had a "Layer Changed" event in the Script Events Manager.
Excuse me and thank you for the help