There have been some recent hints about controlling windows and selecting similar files using AppleScripts, so I thought I would share one that toggles the sort column (kind, date modified etc.) and sort order (a-z or z-a) for a Finder window.
I wanted to do this from the keyboard, so I wrote this script and substituted the appropriate column name as the title, and then assigned it a keyboard shortcut in Quicksilver. Now I can change sort columns and order from the keyboard.
tell application "Finder"
-- could take out the activate if you want
activate
-- In case the column you want to sort by is not visible, turn it on. This example uses the Size column.
if visible of column id size column of list view options of window 1 is false then
set visible of column id size column of list view options of window 1 to true
end if
-- in case that column you want is not currently the one that is selected for sorting, this changes it.
if sort column of list view options of window 1 is not size column then
set sort column of list view options of window 1 to column id size column of list view options of window 1
end if
-- toggles the sort direction, repeatedly invoking the script again has the effect of changing the sort order.
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
end tell
-- switch the name of the column using any of the following names, name column, modification date column, size column, kind, column, label column, comment column to change what you will sort on.
Mac OS X Hints
http://hints.macworld.com/article.php?story=20060418221626696