MacOS – Toggle Finder sort order with AppleScript under Lion 10.7

applescriptfindermacos

For years I've been using this AppleScript to toggle the sort order of a Finder window:

if sort direction of column id size column of list view options of window 1 is normal then
    set sort direction of column id size column of list view options of window 1 to reversed
else
    set sort direction of column id size column of list view options of window 1 to normal
end if

(You can replace size with kind, name, modification date, etc.)

But ever since Lion, this no longer works!

The little arrow in the column header DOES change, but the items do not re-sort.

Any way to get this working?

Best Answer

This is a bit hacky, but changing the sort column before and after changing the sort direction seemed to work on Mountain Lion.

tell application "Finder"
    tell list view options of window 1
        set sort column to name column
        tell column size column
            if sort direction is normal then
                set sort direction to reversed
            else
                set sort direction to normal
            end if
        end tell
        set sort column to size column
    end tell
end tell