I’m trying to set how my documents sort. I’ve got some labeled documents with the Standard view and sorting by that attribute. I want the secondary sort criteria to be modified date. In other apps I can set secondary, etc… sort order by the order I click on the columns.
Select Created column
Select Modified column
Select Label column.
After step 1. the sort order will be Created.
After step 2. the sort order will be Modified, Created.
After step 3. the sort order will be Label, Modified, Created.
Is there any way to achieve this in the Standard view?
This experimental script sorts by kind and addition date.
Usage:
Select a group in the navigate sidebar
Run script
The script opens a new window with the selected group’s children sorted by the criteria you’ve set in the script, in the script below it’s by kind and addition date.
You can change the sort order (ascending or descending) of each criteria independently.
(In the current state of the script one has to set the sort criteria inside the script (instead of setting them in a property block at the start of the script) which is not ideal but necessary. I’ve got an idea how to make it more user friendly but no time at the moment to check whether that would work.)
Click to see the script
-- Experimental script: Sort selected group's children by primary and secondary sort criteria
-- Set your primary sort criteria and its sort order
-- Set your secondary sort criteria and its sort order
-- Select one group in the sidebar
use AppleScript version "2.4"
use framework "Foundation"
use scripting additions
tell application id "DNtp"
try
if exists (root of viewer window 1) then
set theGroup to (root of viewer window 1)
else
error "Please select one group in the sidebar"
end if
show progress indicator "Sorting... " steps 3 as string with cancel button
------------------------------------------------------------------------------
------------------------------------------------------------------------------
-- Set your primary and secondary sort criteria here
-- e.g. addition date, comment, creation date, kind, label, modification date, name, path, rating, tags, unread
set primarySort_Properties to kind of children of theGroup
set primarySort_Ascending to true
set secondarySort_Properties to addition date of children of theGroup
set secondarySort_Ascending to true
------------------------------------------------------------------------------
------------------------------------------------------------------------------
step progress indicator "Fetching properties... "
set theUUIDs to uuid of children of theGroup
set theClass_1 to class of (item 1 of primarySort_Properties)
set theClass_2 to class of (item 1 of secondarySort_Properties)
set theProperties_record to {}
repeat with i from 1 to (count theUUIDs)
set thisProperty_1 to (item i of primarySort_Properties)
if theClass_1 = list then set thisProperty_1 to my tid(my sort_list(thisProperty_1), ",")
set thisProperty_2 to (item i of secondarySort_Properties)
if theClass_2 = list then set thisProperty_2 to my tid(my sort_list(thisProperty_2), ",")
set end of theProperties_record to {property_1:thisProperty_1, property_2:thisProperty_2, uuid_:(item i of theUUIDs)}
end repeat
step progress indicator "Preparing result... "
set theProperties_record_sorted to my sortByProperty1AndProperty2(theProperties_record)
set theSortedChildren to {}
repeat with this_record in theProperties_record_sorted
set thisChild to (get record with uuid (uuid_ of this_record))
set end of theSortedChildren to thisChild
end repeat
set newWindow to open window for record (root of current database)
set search results of newWindow to theSortedChildren
activate
hide progress indicator
on error error_message number error_number
hide progress indicator
if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
return
end try
end tell
on sortByProperty1AndProperty2(theList)
set theArray to current application's NSArray's arrayWithArray:theList
set theSelector_1 to "localizedCompare:"
if my theClass_1 is not in {text, list} then set theSelector_1 to "compare:"
set theDescriptor_1 to current application's NSSortDescriptor's sortDescriptorWithKey:"property_1" ascending:(my primarySort_Ascending) selector:theSelector_1
set theSelector_2 to "localizedCompare:"
if my theClass_2 is not in {text, list} then set theSelector_2 to "compare:"
set theDescriptor_2 to current application's NSSortDescriptor's sortDescriptorWithKey:"property_2" ascending:(my secondarySort_Ascending) selector:theSelector_2
set newList to (theArray's sortedArrayUsingDescriptors:{theDescriptor_1, theDescriptor_2}) as list
end sortByProperty1AndProperty2
on sort_list(theList)
considering numeric strings
set theIndexList to {}
set theSortedList to {}
repeat (length of theList) times
set theLowItem to ""
repeat with a from 1 to (length of theList)
if a is not in theIndexList then
set theCurrentItem to item a of theList as text
if theLowItem is "" then
set theLowItem to theCurrentItem
set theLowItemIndex to a
else if theCurrentItem comes before theLowItem then
set theLowItem to theCurrentItem
set theLowItemIndex to a
end if
end if
end repeat
set end of theSortedList to theLowItem
set end of theIndexList to theLowItemIndex
end repeat
end considering
return theSortedList
end sort_list
on tid(theList, theDelimiter)
set d to AppleScript's text item delimiters
set AppleScript's text item delimiters to theDelimiter
set theList_string to theList as text
set AppleScript's text item delimiters to d
return theList_string
end tid