Layer select or Sample select??

Hi, Thanks for your reply.
I have Very limited experience of scripting, can you point me in the right direction?
Cheers