Finder scripting selection may refer to bogus value not correlated with UI

Number:rdar://9406282 Date Originated:09-May-2011 12:46 PM
Status:Open Resolved:
Product:Finder Product Version:10.7
Classification:Serious Bug Reproducible:Always
09-May-2011 12:46 PM Daniel Jalkut:
NOTE: This is a regression from 10.6.

When the Finder is scripted to reveal a file, and the revelation of that file involves opening a new window, the file is revealed and selected correctly, but the the scripting "Selection" attribute of the Finder is not updated correctly.

1. Make sure that all Finder windows are closed.
2. Open Script Editor
3. Paste and run the following:

tell application "Finder"
	reveal POSIX file "/Applications"
	display dialog "selection is " & selection as string
end tell

RESULT: The Finder will show clearly that the Applications folder is selected in a newly opened window, but the selection is an empty value.

On Mac OS X 10.6 and earlier, the revelation of a file in the Finder causes it to become visible but also selected, and the selection attribute of the Finder properly reflects that.

This change breaks scripts that depend on this outcome.

05-Jun-2012 11:03 AM Daniel Jalkut:
I wanted to add that this problem is more wide-spread than just the use of "reveal" command. The problem is that in general, the Finder's "selection" property is liable to be stale or randomly initialized. Another great example:

1. Create a new finder window.
2. Select anything in the window.
3. Switch to Script Editor and run:

selection of app "Finder"

RESULT: the selection will be falsely reported as either empty or as some past-selected item that is no longer visibly selected.

I would like to add that there is a security aspect to this bug as automated procedures that may include deletion of files are often based on the visible selection in the Finder. In this case, because of the selection property bug, a user may run destructive scripts on a visible selection, only to have the destructive actions applies to a previously selected item.

05-Jun-2012 11:07 AM Daniel Jalkut:
The selection is "fixed" coercing the Finder to cause the selected window to be deselectd and reselected. In my tests, the most reliable, least obtrusive workaround is to switch the active app to a faceless background app, and then back to the Finder:

on WorkaroundSelectionBug()
	activate application "System Events"
	activate application "Finder"
end WorkaroundSelectionBug


But this has an obvious glaring visual side-effect.


fixed in 10.9


Duped as 11611351

Interesting that since you filed this, "Finder" has disappeared as a discrete radarweb product.

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at 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!