Why does the first script below work properly, counting the number of items selected in the frontmost Finder window, while the second does not - returns zero for me in List view.
tell application "Finder"
set s to selection
set c to count s
end tell
but:
tell application "Finder" to set c to (count selection) --> always 0
The problem is that, as it stands, Finder’s selection is a property reference that requires evaluation to offer anything remotely useful. As I mentioned recently in the discussion about Embedded Script Objects for Speed in Processing, both ‘set’ (in the context of a property or variable) and ‘get’ will evaluate a reference. The ‘count’ operation can then be applied to what will then be a regular AppleScript list.
Little wonder that this behaviour creates some confusion - since it’s a bit lame. Other applications (Mail, Address Book, iPhoto, iTunes, etc.) manage to evaluate ‘selection’ without an explicit ‘get’ - as did the pre-Mac OS X Finder (which even offered filtering, such as: items of selection whose name contains “some text”).
(Incidentally, some applications, such as TextEdit and Safari, don’t yet feature a selection property.)