This script changes the current Finder view to List view, enables all the columns there, and then rearranges them.
The problem is that I don’t understand the last step: how to rearrange columns. This seems to be trivial (see https://help.apple.com/applescript/mac/10.9/#apscrpt2694), but I didn’t figure it out yet.
(* Finder: Change List view options
https://discussions.apple.com/thread/3533331, 2011
Works with Sonoma 14.7.1
*)
tell application "Finder"
activate
tell the front Finder window
set the current view to list view
end tell
tell list view options of front Finder window
set width of column name column to 250
end tell
tell application "System Events" to tell process "Finder"
tell menu item "Show View Options" of menu of menu bar item "View" of menu bar 1 to if exists then click
tell checkbox "Date Modified" of group 1 of window 1 to if value is 0 then click
tell checkbox "Date Created" of group 1 of window 1 to if value is 0 then click
tell checkbox "Date Last Opened" of group 1 of window 1 to if value is 0 then click
tell checkbox "Date Added" of group 1 of window 1 to if value is 0 then click
tell checkbox "Size" of group 1 of window 1 to if value is 0 then click
tell checkbox "Kind" of group 1 of window 1 to if value is 0 then click
tell checkbox "Version" of group 1 of window 1 to if value is 0 then click
tell checkbox "Comments" of group 1 of window 1 to if value is 0 then click
tell checkbox "Tags" of group 1 of window 1 to if value is 0 then click
end tell
tell the front Finder window
set the index of column size column to 2
end tell
end tell
The individual columns are elements of the list view options of a Finder window, not the Finder window itself, so they would be targeted the same as where you are setting the column width.
1 Like
@red_menace Hello, thanks. Now I have figured it out, but I need anoter help (see below)
tell application "Finder"
activate
tell the front Finder window
set the current view to list view
end tell
tell list view options of front Finder window
set width of column name column to 250
end tell
tell application "System Events" to tell process "Finder"
tell menu item "Show View Options" of menu of menu bar item "View" of menu bar 1 to if exists then click
tell checkbox "Date Modified" of group 1 of window 1 to if value is 0 then click
tell checkbox "Date Created" of group 1 of window 1 to if value is 0 then click
tell checkbox "Date Last Opened" of group 1 of window 1 to if value is 0 then click
tell checkbox "Date Added" of group 1 of window 1 to if value is 0 then click
tell checkbox "Size" of group 1 of window 1 to if value is 0 then click
tell checkbox "Kind" of group 1 of window 1 to if value is 0 then click
tell checkbox "Version" of group 1 of window 1 to if value is 0 then click
tell checkbox "Comments" of group 1 of window 1 to if value is 0 then click
tell checkbox "Tags" of group 1 of window 1 to if value is 0 then click
end tell
tell application "System Events" to tell process "Finder"
click (first button of window 1 whose description is "close button")
end tell
tell list view options of front Finder window
set the index of column size column to 2
end tell
end tell
So, now it works, but to really see the columns have been rearranged, it is required to “update” them somehow. For example, you can visit another directory and then return back. That is, once you return back, you will see the “Size” column is now the 2nd one. But of course, I would like to automate it somehow. I tried
tell application "Finder" to tell front window to update every item
but it didn’t help.
The update
command is used mainly for file items. There isn’t a command to refresh the window, but a couple of options would be to create another Finder window in front and then close the existing (although it would need to have the same view settings) or fake the “go to another directory and back” thing by changing the target, for example:
tell application "Finder"
tell front Finder window
set currentTarget to its target
set current view to list view
set options to its list view options
end tell
activate
delay 0.5
tell application "System Events" to tell process "Finder" -- show columns
tell menu item "Show View Options" of menu of menu bar item "View" of menu bar 1 to if exists then click
delay 0.5
repeat with boxName in {"Date Modified", "Date Created", "Date Last Opened", "Date Added", "Size", "Kind", "Version", "Comments", "Tags"} -- column names
if boxName is in {"Date Modified", "Date Created", "Size", "Kind"} then
tell checkbox boxName of group 1 of window 1 to if value is 0 then click -- check desired columns
else
tell checkbox boxName of group 1 of window 1 to if value is 1 then click -- uncheck others
end if
end repeat
delay 0.5
tell menu item "Hide View Options" of menu of menu bar item "View" of menu bar 1 to if exists then click
end tell
tell options
set width of column name column to 250
set the index of column size column to 3
end tell
tell front Finder window -- workaround to refresh window to current column order
set its target to container of currentTarget -- previous...
set its target to currentTarget -- ...and back
end tell
end tell
(You may need to adjust the delays - GUI scripting is finicky, and I don’t normally use list view.)
1 Like
Wow, thanks a lot. It is much better than my original version.
@red_menace Do you know how to access “Date Last Opened” and “Date Added” columns?
Here is the work-in-progress version of the script. It works fine except that I don’t understand how to access those two columns.
tell application "Finder"
tell front Finder window
set currentTarget to its target
set current view to list view
set options to its list view options
end tell
activate
delay 0.5
tell application "System Events" to tell process "Finder" -- show columns
tell menu item "Show View Options" of menu of menu bar item "View" of menu bar 1 to if exists then click
delay 0.5
repeat with boxName in {"Date Modified", "Date Created", "Date Last Opened", "Date Added", "Size", "Kind", "Version", "Comments", "Tags"} -- column names
if boxName is in {"Date Modified", "Date Created", "Date Last Opened", "Date Added", "Size", "Kind", "Version", "Comments", "Tags"} then
tell checkbox boxName of group 1 of window 1 to if value is 0 then click -- check desired columns
else
tell checkbox boxName of group 1 of window 1 to if value is 1 then click -- uncheck others
end if
end repeat
delay 0.5
tell menu item "Hide View Options" of menu of menu bar item "View" of menu bar 1 to if exists then click
end tell
tell options
set width of column name column to 250
set width of column modification date column to 1
set width of column creation date column to 1
--set width of column last opened date column to 1
--set width of column added date column to 1
set width of column size column to 1
set width of column kind column to 1
set width of column version column to 1
set width of column comment column to 1
set width of column label column to 1
set the index of column name column to 1
set the index of column modification date column to 2
set the index of column creation date column to 3
--set the index of column last opened date column to 4
--set the index of column added date column to 5
set the index of column size column to 6
set the index of column kind column to 7
set the index of column version column to 8
set the index of column comment column to 9
set the index of column label column to 10
end tell
tell front Finder window -- workaround to refresh window to current column order
set its target to container of currentTarget -- previous...
set its target to currentTarget -- ...and back
end tell
end tell
I tried to record a macro to figure it out, but macro recorder seems to treat them as the “Name” column, for some reason. For example, here I turned on the “Date Created” column and then “Date Last Opened” and “Date Added”. As you can see, the 2nd and 3rd set
lines don’t look useful:
tell application "Finder"
activate
set visible of column id creation date column of list view options of Finder window 1 to true
set visible of column id name column of list view options of Finder window 1 to true
set visible of column id name column of list view options of Finder window 1 to true
end tell
I only see those 8 enumeration constants, so it looks like you are stuck with using GUI scripting, for example (Sonoma):
tell application "System Events" to get properties of UI elements of scroll area 1 of splitter group 1 of splitter group 1 of window "/System/Library/CoreServices" of application process "Finder"
… and get the desired items from there.
The column indexes would change depending on their location, so you would need to check again after moving anything.
1 Like
Thanks a lot, @red_menace. I never worked with Automator and AppleScript prior this week, and to be honest, I’m very discouraged now.
First I tried to enable/disable List view columns using Automator. And it seems there is a bug that prevents it: Automator workflow to force the same view for all the subfolders
Then I tried AppleScript and GUI scripting, with your great help, and it turns out the two columns, for some really unexpected reason, require a special (and most probably, very fragile) way to access them.
Very frustrating.