Saturday, July 4, 2020

#1 2020-05-04 05:59:05 pm

sebrady
Member
Registered: 2005-09-13
Posts: 36

sort window 1 by name

this used to be easy and work 15 years ago, what happened. I just need to sort a window by name or modification date. Here is what I have and it does not work.


Applescript:

   tell application "Finder"
       set sort column of list view options of Finder window 1 to column name
   end tell

Offline

 

#2 2020-05-08 06:35:56 am

KniazidisR
Member
Registered: 2019-03-03
Posts: 1259

Re: sort window 1 by name

I don't know for 15 years. As is now:

Applescript:


tell application "Finder"
   activate -- This need only for testing purposes (visualization the result)
   tell front Finder window
       set aFolder to target -- remember the folder, need only for testing purposes
       if current view ≠ list view then set its current view to list view -- making sure
       tell (its list view options) to set sort column to column id name column
   end tell
   -- The following 3 code lines need only for testing purposes (visualization the result)
   close front Finder window -- close not updated folder's window
   open aFolder -- open updated folder's window
   display dialog "Now your front Finder window IS SORTED BY NAME"
end tell

NOTE:
1) instead of column id name column you can use column name column
2) you can omit "visualization" code lines
3) I guess, you can omit "making sure" code line too:

Applescript:


tell application "Finder" to tell front Finder window to tell (its list view options)
   set sort column to column name column
end tell

The list view is sorted, but with this 2nd snippet you will see the changes only when you will close and reopen the given window (as list view manually if need).

It is your choice, what you need - sorting foreground (my 1st code) or sorting background (2nd code)

Using the syntax similar to your original script, I can write my 2nd script this way:

Applescript:


tell application "Finder"
   set sort column of list view options of Finder window 1 to ¬
       column name column of list view options of Finder window 1
end tell

Last edited by KniazidisR (2020-05-08 07:17:49 am)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)