As you say you have to use an index in the layers list, but AFAIK you can get the nth item of a list using list-ref:
Note: it is usually a better idea to declare your script has taking a second argument that will be the target layer (SF-LAYER), and it will be set to the active layer when the script is called from the UI. Otherwise you can be looking for an active layer when there is none (because the active "drawable" is something else, like a channel).
Code:
> (list-ref '(a b c d) 2)
c
Note: it is usually a better idea to declare your script has taking a second argument that will be the target layer (SF-LAYER), and it will be set to the active layer when the script is called from the UI. Otherwise you can be looking for an active layer when there is none (because the active "drawable" is something else, like a channel).