Finder-view scripting is a bit problematic to the consternation (profanity elided) of many Mac scripters.
Some things work, and some things don't.
Some things only work after you refresh a window.
To add and remove elements to a window you'll have to use GUI-Scripting as in script 1 below.
For more examples see script 2.
-------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2015/10/01 13:04
# dMod: 2016/08/27 15:54
# Appl: System Events
# Task: Set List View Attributes
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @System_Events, @Set, @List-View, @Attributes
-------------------------------------------------------------------------------------------
setFrontFinderWindowToListView()
tell application "System Events"
tell application process "Finder"
set frontmost to true
if (value of attribute "AXSubrole" of front window is "AXSystemFloatingWindow") = false then
keystroke "j" using command down
set theClock to 0
repeat while front window's subrole is not "AXSystemFloatingWindow"
if theClock ≥ 0.5 then
beep
error "Problem opening window list-view prefs!"
else
set theClock to theClock + 0.1
delay 0.1
end if
end repeat
end if
tell (first window whose subrole is "AXSystemFloatingWindow")
tell group 1
if (exists of checkbox "Date Modified") = false then
setFrontFinderWindowToIconView() of me
delay 0.15
setFrontFinderWindowToListView() of me
delay 0.15
end if
end tell
tell checkbox "Always open in list view"
if its value = 0 then
click it
end if
end tell
tell checkbox "Browse in list view"
if its value = 0 then
click it
end if
end tell
tell (first pop up button whose name is "Arrange By:")
if value ≠ "None" then
click
tell menu 1
click menu item "None"
end tell
end if
end tell
tell (first pop up button whose name is "Sort By:")
if value ≠ "Name" then
click
tell menu 1
click menu item "Name"
end tell
end if
end tell
tell group 1
tell checkbox "Date Modified"
if its value = 1 then
click it
end if
end tell
tell checkbox "Date Created"
if its value = 0 then
click it
end if
end tell
tell checkbox "Date Last Opened"
if its value = 1 then
click it
end if
end tell
tell checkbox "Date Added"
if its value = 1 then
click it
end if
end tell
tell checkbox "Size"
if its value = 1 then
click it
end if
end tell
tell checkbox "Kind"
if its value = 1 then
click it
end if
end tell
tell checkbox "Version"
if its value = 1 then
click it
end if
end tell
tell checkbox "Comments"
if its value = 1 then
click it
end if
end tell
tell checkbox "Tags"
if its value = 1 then
click it
end if
end tell
tell checkbox "Use relative dates"
if its value = 0 then
click it
end if
end tell
tell checkbox "Calculate all sizes"
if its value = 1 then
click it
end if
end tell
tell checkbox "Show icon preview"
if its value = 1 then
click it
end if
end tell
end tell
keystroke "j" using command down
end tell
end tell
end tell
-------------------------------------------------------------------------------------------
--» HANDLERS
-------------------------------------------------------------------------------------------
on setFrontFinderWindowToListView()
tell application "Finder"
tell front Finder window
set its current view to list view
end tell
end tell
end setFrontFinderWindowToListView
-------------------------------------------------------------------------------------------
on setFrontFinderWindowToIconView()
tell application "Finder"
tell front Finder window
set its current view to icon view
end tell
end tell
end setFrontFinderWindowToIconView
-------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2010/10/09 12:45
# dMod: 2017/02/20 05:11
# Appl: Finder
# Task: Resize front window to large default size.
# : Special-Filters for various windows.
# Libs: None
# Tags: @Applescript, @Finder, @Resize, @Window, @Filter
-------------------------------------------------------------------------------------------
property defaultWindowBounds : {0, 23, 844, 1196}
property defaultSideBarWidth : 140
-------------------------------------------------------------------------------------------
try
set kmWorkng to ((path to documents folder as text) & "Working Items (Current):Working ⇢ Keyboard Maestro:")
set safariBookmarksRoot to ((path to documents folder as text) & "Bookmarks_Safari:")
set sdScriptSnapShots to ((path to documents folder as text) & "Code_Projects:Script_Debugger:Script-Snap-Shots:")
set webArchives to ((path to documents folder as text) & "Web Archives:")
set workingItemsCurrent to ((path to documents folder as text) & "Working Items (Current):")
tell application "Finder"
if (count of windows) > 0 then
tell front window
set winTarget to (its target) as text
if current view ≠ list view then
set current view to list view
end if
if winTarget = kmWorkng then
set bounds to {0, 23, 1040, 1196}
else if winTarget = sdScriptSnapShots then
--» Script Dumps folder.
set bounds to {0, 23, 1075, 1196}
tell its list view options
width of column id name column
set width of column id name column to 900
set width of column id modification date column to 141
set width of column id creation date column to 141
set width of column id modification date column to 141
set width of column id size column to 97
end tell
else if winTarget = workingItemsCurrent then
--» Working Items folder.
tell its list view options
set width of column id name column to 413
set width of column id modification date column to 141
set width of column id creation date column to 141
set width of column id modification date column to 141
set width of column id size column to 97
end tell
set bounds to {0, 23, 900, 1196}
else if winTarget starts with safariBookmarksRoot then
--» Safari Bookmarks folder.
tell its list view options
set width of column id name column to 675
set width of column id creation date column to 181
end tell
set bounds to {0, 23, 1032, 1196}
else if winTarget starts with webArchives then
--» Web Archives folder.
tell its list view options
set width of column id name column to 900
set width of column id creation date column to 181
end tell
set bounds to {437, 23, 1482, 1196}
else
--» Generic.
tell its list view options
set width of column id name column to 413
set width of column id modification date column to 141
set width of column id size column to 97
end tell
set bounds to defaultWindowBounds
end if
if toolbar visible = false then set toolbar visible to true
if statusbar visible = false then set statusbar visible to true
if sidebar width ≠ 135 then set sidebar width to defaultSideBarWidth
end tell
end if
end tell
on error errMsg number errNum
beep
tell me to display dialog "Error: " & errMsg & return & "Error Number: " & errNum
end try
-------------------------------------------------------------------------------------------