Verify if a selection exists

Sorry to bother You all with such a question, but how can I verify if an active selection exists in a document?
Actually I seem to be able to verify it by way of a whack try-catch-construction set to some selection-property (which returns undefined if no Selection exists), but obviously a more simple way should exist. 
I want to do so in order to set up a condition to delete the Layer Mask if no Selection is active on creating an Adjustment Layer (a basic setting seemingly lost in CS4).
Thanks for any suggestions.

> A nifty construction, but it seems to indicate that the fact of a Selection being active is indeed not an easily accessed property.
This is true.
> I wonder if
>
> var myDocument = app.activeDocument;
> try {var forgetIt = myDocument.selection.bounds}
> catch (a) {alert (has no selection)};
>
> might not be shorter after all?
>
Marginally shorter, but bad form. A general rule for good programming is that
you do not use try/catch for stuff like this. There are times when you
absolutely have to because there is no other choice or times when it saves you
20 or 30 lines of code. But, in this case, the hasSelection function is small
enough that there is no real benefit to doing the try/catch.
[email protected] wrote:
> Likely the reason X used the form shown in the first example is that earlier
versions of Photoshop had problems when requesting selection bounds and it seems
I recall some versions where it didn't work at all.
Selection.bounds didn't work in CS2 and accessing the property would always
raise an exception. I'm not really sure how I implemented earlier versions but
using the history state stack trick has simplified a lot of code.
-X

Similar Messages

Maybe you are looking for

  • Time Machine and "might be a problem with your network"

    Hi! My Power Mac is from 2008, and I'm in the middle of replacing my hard drive. Here's a summary of what I've gone through, including various trouble shooting... OK, the hard drive dies (all of which I wrote about in an earlier thread and, I think,

  • New for ABAP in functional upgrade from 4.6c to ECC6.0

    i want to know the enhancements, additions and changes in the technical side/ABAP , when moved from 4.6c to ECC6.0 in case of FUNCTIONAL UPGRADE only.... our compny has done FUNCTIONAL UPGRADE so far..whats new for technical ppl like us apart from ch

  • Good news!   Uploads for collections reenabled in PSM.

    Well, for those institutions new to iTunes U, you can now upload content to Apple's servers to create collections!  This option was removed in early 2009 forcing institutions to provide their own RSS and content hosting. Dear iTunes U Administrator,

  • How to make a Jtree expandable

    Hi have a JTree and when I expand the tree and catch an exption hence not adding any children I would like the node that I have expanded to autamatically be collapsed, and ready for a future expand, as I have a situation were a node in the tree might

  • Qosmio G50-12q - Vista does not load after connecting external USB keyboard

    I have acquired a keyboard enermax acrilux usb and have connected the taken keyboard to the qosmio g50 12q at the same one where an other keyboard was attacked usb and that it worked without problems. After to start the PC with keyboard eneramx conne