MacOS – Applescripts not working in Finder since Mavericks

applescriptfindermacos

I have a bunch of Applescripts that do things like change sort column in Finder windows, but they've stopped working since Mavericks.

If I close and reopen the window, then the change takes effect, but this is annoying.

Is this a bug? Is there a workaround?

E.g.,

tell application "Finder"
tell list view options of window 1
    set sort column to name column
    tell column kind 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 kind column
end tell
end tell

Best Answer

This looks like a bug. I've tried rewriting the script various ways but the change only seems to take effect for new windows.

So here is a horribly hacky way to get this to work.

tell application "Finder"
    tell list view options of window 1
        tell column kind 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 kind column
    end tell
    set currentPosition to position of window 1
    set currentTarget to target of window 1
    make new Finder window to currentTarget
    set position of window 1 to currentPosition
    close window 2
end tell