Do NOT use selectedLayers - rather than providing information about the selected layers, it restricts information about layers to the selected ones.
At least it soon will, since that bug in Photoshop just got fixed.