AppleScript: Rearrange columns in Finder's List view

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

Is index a global setting, maybe? In the link, it’s tell application Finder.

1 Like

I’m not really understand AppleScript. Could you show what to change exactly?

Something like this - the only lines changed are the last few. I can’t test it right now, so it might not work.

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
	
	set the index of column size column to 2
end tell
1 Like

Yes, unfortuately Finder got an error:

Can’t make size column into type integer.

1 Like

I have figured it out, but I need anoter help (see below) :slight_smile:

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.

1 Like

Solved here: Rearrange columns in Finder's List view - AppleScript | Mac OS X - MacScripter