Or move Layer 6 above layer 3 in the layer stack then merge down. The steps would also be like the process you show above. The script need have some logic to know which two layer need to be merged and position in the layer stack. If You target two layers before running your script Your script can get which layers are targeted and work on them. Order the top selected layer above the bottom targeted layer and merge down. Its so easy to do manually drag 6 above 3 and Ctrl+E. I do not know why you would want to script that.
Script and actions should be use to automated processes you do regularly. Perhaps batch process. Having to manually target two layer then run a script is not really an automated task for it requires your interaction.