I wrote the Lisp above to deal with texts according to OP's request. So the program checks first if there is anything selected, next it looks for the type of the selected entity.
Yes, you can expand that second check by adding some ORs, or you could use wildcards.
Another option could be to skip all these checks. Of course, in this case it is the user's responsibility to make correct selections.