Thursday, December 13, 2018

#1 2015-11-13 12:50:06 pm

Skillet
Member
Registered: 2010-01-11
Posts: 133

Finder Sort by Date Added

We have had sort by "Date Added" in the Finder now for a few years but there hasn't been a way to show this yet through AppleScript that I am aware of.  Has anyone been able to script to show the "Date Added" column in list view?

Applescript:

tell application "Finder"
activate
tell list view options of the front Finder window
set properties to {calculates folder sizes:false, shows icon preview:false, icon size:large icon, text size:12, uses relative dates:true, sort column:name column}

tell column name column
set properties to {index:1, sort direction:normal, width:280}
end tell
tell column size column
set properties to {index:2, sort direction:normal, width:72, visible:true}
end tell
tell column modification date column
set properties to {index:3, sort direction:normal, width:120, visible:true}
end tell
tell column creation date column
set properties to {index:4, sort direction:normal, width:120, visible:true}
end tell
tell column kind column
set properties to {index:5, sort direction:normal, width:120, visible:false}
end tell
tell column label column
set properties to {index:6, sort direction:normal, width:72, visible:false}
end tell
tell column version column
set properties to {index:7, sort direction:normal, width:72, visible:false}
end tell
tell column comment column
set properties to {index:8, sort direction:normal, width:240, visible:false}
end tell
set sort column to size column
end tell

tell the front Finder window
set current view to list view
set zoomed to false
end tell
end tell


macOS 10.13.4

Offline

 

#2 2015-11-13 02:38:04 pm

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3290

Re: Finder Sort by Date Added

You may use this code :

Applescript:

set {mt, mi} to {5, 2}
set p2Finder to path to application "Finder"
set ShowPresentationOptions_loc to localized string "N35" in bundle p2Finder

tell application "System Events" to tell process "Finder"
   set frontmost to true
   
   tell menu bar 1 to tell menu bar item mt to tell menu 1
       -- log (get name of menu items)
       -- log (get name of menu item mi)
       click menu item mi
       set showHide to name of menu item 21
   end tell
   delay 0.1
   if showHide is ShowPresentationOptions_loc then
       keystroke "J" using {command down}
       repeat 20 times
           delay 0.2
           -- log (get subrole of windows)
           -- log (get properties of first window)
           if exists (first window whose subrole is "AXSystemFloatingWindow") then exit repeat
       end repeat
   end if
   tell (first window whose subrole is "AXSystemFloatingWindow")
       -- log (get class of UI elements) --> {button, checkbox, group, checkbox, pop up button, static text, pop up button, static text, button, static text}
       tell first group
           -- log (get class of UI elements) --> {checkbox, static text, pop up button, checkbox, checkbox, static text, static text, radio group, checkbox, checkbox, checkbox, checkbox, checkbox, checkbox, checkbox, checkbox, checkbox, button, button}
           -- log (get title of checkboxes) (*Calculer toutes les tailles, Utiliser les dates relatives, Version, Tags, Date de modification, Taille, Type, Commentaires, Date de création, Utiliser un aperçu comme icône, Date de dernière ouverture, Date de l’ajout*)
           if value of attribute "AXValue" of checkbox -1 = 0 then
               click checkbox -1
           end if
       end tell
   end tell
end tell

Yvan KOENIG running El Capitan 10.11.1 in French (VALLAURIS, France) vendredi 13 novembre 2015 21:37:59

Online

 

#3 2015-11-15 01:11:04 am

ccstone
Member
Registered: 2009-02-07
Posts: 413

Re: Finder Sort by Date Added

Hey Skillet,

Did you flatten your script?  The forum will manage indentation nicely and make it easier to read.

Unfortunately Apple has done little to improve Finder scripting for about a decade...

-Chris

Offline

 

#4 2015-11-15 02:32:11 am

ccstone
Member
Registered: 2009-02-07
Posts: 413

Re: Finder Sort by Date Added

Here's a pretty comprehensive look at setting the window list-view-options with System Events.

It's pokey, but it's faster than setting them manually.

(I know some of these can be set without SEV, but I was trying to be thorough.)

Applescript:


-------------------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2015/10/01 13:04
# dMod: 2015/11/15 02:14
# Appl: System Events
# Task: Set List View Attributes
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @System_Events, @Set, @List-View, @Attributes
-------------------------------------------------------------------------------------------

tell application "Finder"
   tell front Finder window
       if its current view ≠ list view then
           set its current view to list view
           delay 0.1
       end if
   end tell
end tell

tell application "System Events"
   tell application process "Finder"
       set frontmost to true
       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
       
       tell (first window whose subrole is "AXSystemFloatingWindow")
           
           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 = 1 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 = 0 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

-------------------------------------------------------------------------------------------

--
Chris
_________________________________________________________
{ MacBookPro6,1 · 2.66 GHz Intel Core i7 · 8GB RAM · OSX 10.11.1 }
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

Offline

 

#5 2018-01-04 12:53:21 pm

Skillet
Member
Registered: 2010-01-11
Posts: 133

Re: Finder Sort by Date Added

Hi Chris and Yvan,
Thanks for your reply, I always hate when I miss emails of replies to my questions. I  came back here searching for the same topic again and found my own question through Google, it is funny how much that keeps happing over the years.

Anyway for some strange reason it is not sorting by size. Ideally I would like to sort by date added.

Applescript:

       set sort column to size column

--    set sort column of list view options of Finder window 1 to modification date column

It appears that "Date Added" and "Tags" don't have an AppleScript option to sort by in macOS 10.11.6 - 10.13.2.

Last edited by Skillet (2018-01-04 12:53:45 pm)


macOS 10.13.4

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)