Determine If Tree Selection is a Folder

How would I figure out through script if a folder is selected on tag tree in perspective? I know how to do this in Vision but I am having a hard time figuring it out using the perspective tree.

For an example, in the screen shot below, how do I determine that the TEST PAD or ALL folder is selected. I need to be able to determine if a folder is selected or an actual item under the folder.