What is the specifier for the selected file or fold in a finder window

I can’t seem to get the specifier right. I want to run a script to get the name of the selected file or folder in a finder window. I think it should go something like this.

Tell application “Finder” to get name of selection in window 1

But that gives me this error. “Finder got an error: Can’t get selection of Finder window id 76.”

And the following gives me a syntax error.

Tell application “Finder” to get name of selected item in window 2

Thanks for the help

Hi,

forget the window


tell application "Finder" to get name of item 1 of (get selection)