How to disable a button when no files are selected?

Many of the button menus on the default toolbars do this, but I can'f figure out how to replicate the behavior. Thanks.

Using @disablenosel:

Thanks Leo. I had a look around, but wasn't using the right search terms.