Myriad Tables Questions (3)

Sorting doesn’t seem to be working in Myriad Tables.

This is from a script that uses the ###) method to sort file names, and display options to the users. It’s been working for a few years now.

But today I noticed that while the script works, the items are not sorted. I’ve tried various sort methods and no change.

→ Script Debugger: 8.0.3 (8A42)
→ Myriad Tables Lib: 1.0.12 (66)
→ Mac OS: 11.6 (20G165)

use AppleScript version "2.4"
use scripting additions
use script "Myriad Tables Lib" version "1.0.7"
use script "FileManagerLib" version "2.2.1"
property lastTablePosition : {25, 25}
property paletteScriptFolder : ""
property myName : ""

set tableData to {¬
	{"026)", "Close all but first Finder windows"}, ¬
	{"011)", "textFromSelectedMessages"}, ¬
	{"001)", "Delete Unwanted CalendarMail Emails"}, ¬
	{"003)", "Missing TV Listings"}, ¬
	{"003)", "AppVersionsApple", ""}, ¬
	{"100)", "zOpen This Scripts Folder"} ¬

set highlightedRows to {2, 4, 6, 8}
set tablePrompt to "Select a script to run"
set tableTitle to "Script Pallet"
set cancelName to "Close Pallet"
set extraButton to "Reset"

   set myTable to make new table with data tableData ¬
      with prompt tablePrompt ¬
      with title tableTitle ¬
      empty selection allowed true ¬
      multiple lines allowed false ¬
      row template {missing value, ""} ¬
      with double click means OK
   modify table myTable ¬
      highlighted rows highlightedRows ¬
      extra button name extraButton ¬
      cancel button name cancelName
   modify columns in table myTable ¬
      sorting data column 1 ¬
      sort method sort case insensitive
   set tableResult to display table myTable ¬
      with extended results
   end repeat

The dictionary doesn’t make it clear, but what you’re actually setting there is how the table will be sorted if you click on the title of that column.

Well, this is very odd, then. Because with the same script running in the same folder on my older Macs it displays the files in the ###) sorted order, but on this one they’re in a random order.

The list is generated by the handler below, and I could add a sort command, but it seemed to work flawlessly before.

on BuildTableFromScripts(folderWithScripts)
   set myFiles to objects of folderWithScripts ¬
      searching subfolders false ¬
      include invisible items false ¬
      include folders true ¬
      include files true ¬
      result type files list
   set scriptNameExts to {"scpt", "scptd", "app"}
   set tableData to {}
   set highlightedRows to {}
   repeat with thisFile in myFiles
      set fileInfo to parse object thisFile with HFS results
      set {fileName, nameExt, nameText, fileKind} to ¬
      {full_name, name_extension, name_stub, file_kind} of fileInfo
      set AppleScript's text item delimiters to {")"}
      set displayText to (the rest of text items of nameText) as text
      if displayText is "" then set displayText to nameText
      if fileName is not myName then
         if nameExt is in scriptNameExts or fileKind is "Alias" then
            set the end of tableData to {fileName, displayText, thisFile as text}
            set aFolder to object is folder thisFile
            set the end of tableData to {fileName, "  -->" & displayText, thisFile as text}
            set the end of highlightedRows to count of tableData
         end if
      end if
   end repeat
   return {tableData, highlightedRows}
end BuildTableFromScripts

That suggests it’s a change in behavior of the underlying macOS code. I’ve looked at my code, and I’m setting how the column should be sorted, but not that it should be sorted initially. (That plays havoc with initial selection, apart from anything else.)

Is it possible that objects of was doing a sort? That’s what’s feeding the table in the first place.

The underlying file system returns names sorted under HFS, but not under APFS. That might explain the change you’re seeing.

Got it. Luckily, thanks to help from this forum, I’ve got a quick sorting handler in a library!