Another suggestion, not sure how useful.
If you switch your move tool to auto-select layer mode, then make a small selection on some blank area and move it around by holding space, it will select the layers that fall underneath the selection rectangle, from there you can use a script to return the selected layers.
Though I don't know of any way to do the selection bit in script.