Is there a (better) way to determine if a selection is present in a layer in Photoshop without having using a try/catch on the selection.bounds?
try
{
var sel = app.activeDocument.selection.bounds;
}
catch(e)
{
var sel = undefined;
alert("No selection");
}
if (sel) alert(sel);
If there is no selection instead of the (expected) undefined bounds getting returned, I just get the error 1302: No such element. Hence the need for a try/catch.
I was running into this too, and while I didn't find a way around using a try..catch, I just added a simple active() function to the Selection prototype that I could test.
This way, you can just call
app.activeDocument.selection.active()to see if something is selected.The ternary operator in the try section is there in case they ever fix Selection.bounds to report undefined in the future.