Go to the top-most layer in a set of clipping masked-layers
Hi all; I am new to coding in general and of course Photoshop scripting.
I am wondering how I could select the top-most (or in my case specifically, the second-to-top most) layer in a stack of clipping masks. Refer to the picture below; say I am currently on Layer 4.

When I run the script, it needs to jump to Layer 6, and add a new layer. Note that this stack could be much bigger, but will never be smaller than 2. (And also instead of being on Layer 4, I might be on Layer 1 (the base layer of the stack).)
Of course it might also be in a group, and that group might be in a group, etc, and that there are also multiple clipping masks in the document.
I have a script that goes to the base layer of the stack, but unfortunately I don't know how to go the other way, and this script only works with the first stack that appears in the document.
Any guidance to set me in the right direction would be helpful!
