Accept as input an item selected by mouse over and right-click

I have a few AppleScripts and OS X 10.6.4 Services containing AppleScripts, which take a Finder selection to process further. This is a simplified example of the Finder selection input:


tell application "Finder"
	set selectCount to count selection as list
	if selectCount = 0 then
		display alert "Nothing was selected"
	else
		display dialog (selectCount as text) & " selected"
	end if
end tell

This works well when there is a multiple item selection, or a single item (file or folder) selected by left-clicking on it. I can then right-click on the selection to access a service to process the selection.

However, if I only mouse over one item and right-click on it to access a service, then no selection is recorded. This is contrary to the normal behaviour when mousing over and right-clicking on an item in the Finder, for instance to assign a label.

How can I modify the script to make it accept the input of a single item selected by mousing over and right-clicking on it? Please help me.

This strange behaviour is only in the list view. It seems as a bug. Fixed that way:

tell application "Finder"
	activate
	tell window 1
		if current view is list view then
			set current view to icon view
			set theCount to count of (selection as list)
			set current view to list view
		else
			set theCount to count of (selection as list)
		end if
	end tell
	
	if theCount = 0 then
		display alert "Nothing is selected"
	else
		display dialog (theCount as text) & " items is selected"
	end if
	activate
end tell

Thank you

Browser: Safari 605.1.15
Operating System: macOS 10.14