I'm trying to do a simple applescript that used to work but does not seem to work anymore. I am using macos Sonoma and Sequoia.
I was hoping for a very simple applescript that would:
sort by name column ascending
set the name column width to 400
in the script below it does not have errors however it also does not work.
some people suggest applescript does not work as well in the new operating systems for this purpose
I would be happy to use any method necessary to accomplish this goal so it does not have to be applescript.
Thanks Dave
tell application "Finder"
if (count of Finder windows) = 0 then return
tell front Finder window
if current view is not list view then set current view to list view
end tell
try
tell list view options of front Finder window
-- Name column: wide and sorted by name (ascending)
tell column name column
set width to 400
set sort direction to normal
end tell
-- Date Modified column
try
tell column modification date column
set width to 150
set sort direction to normal
end tell
end try
end tell
on error errMsg number errNum
-- swallow Finder’s “access not allowed”/permissions issues
end try
end tell
There's a bug in Finder's sort AppleScript support -- the workround, IIRC, is to set the options then close the window and re-open it. Try this (I've commented out the Date Modified column section):
tell application "Finder"
if (count of Finder windows) = 0 then return
tell front Finder window
if current view is not list view then set current view to list view
end tell
set theTarget to target of front window
try
tell list view options of front Finder window
-- Name column: wide and sorted by name (ascending)
set sort column to name column
tell column name column
set width to 400
set sort direction to normal
end tell
-- Date Modified column
(*
try
tell column modification date column
--set width to 150
--set sort direction to normal
end tell
end try
*)
end tell
on error errMsg number errNum
-- swallow Finder’s “access not allowed”/permissions issues
end try
close front window
open theTarget
end tell
Wow - you did it - nice fix - Thanks so much for your help!
On Sequoia with M4 MacBook - I had to make one small addition - I needed to put a delay between close window and open the target - in order to get the window to reopen I guess because M4 is so fast.