Asking the Finder for the current selection, returns the wrong file

Originator:levi.nunnink
Number:rdar://10561771 Date Originated:10-Dec-2011 07:52 PM
Status:Open Resolved:
Product:Mac OS X Product Version:10.7.2
Classification:Serious Bug Reproducible:Yes
 
Summary:  

I've uncovered what appears to be a bug where you need to focus a window twice in order for Finder to return the correct result over the scripting bridge or AppleScript. This only happens when opening a folder from the desktop or another space.

Steps to Reproduce:

1. Close, hide or minimize all windows until the desktop is showing.
2. Open any folder on the desktop, a new finder window will appear. Select any file in that finder window by clicking on it once.
3. Open your AppleScript Editor and run the following script:

tell application "Finder"
    return selection
end tell

Expected Results:

The script should return the path to the selected item in the foremost window of the Finder.

Actual Results:

The script will return only the path to the folder on the desktop, not the selected file in the finder window.

If you refocus the window, or click on the file again, everything works as expected and the script returns the correct path.

Regression:

The problem happens every time.

Notes:

Comments

Apple has responded to This is a known bug and a duplicate of this issue: http://openradar.appspot.com/10362028

By levi.nunnink at Dec. 14, 2011, 4:04 a.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!