My initial approach was to simulate with KBM the actions that I was doing manually. Hence, I thought that before right-clicking on an icon, I should verify that there was an icon there to accept the right-click. I wanted a right-click to be able to access the Open With menu. But KBM has a built-in "Finder Open With" action which will do what I want in a single step and has all the proper validity checking built in. It won't run if there is no selection in Finder.