I recently asked about how to capture the Recent Files list of an app as a list, but it turned out that was not the solution to my real problem. Fortunately, I found a simple solution that may be useful in other cases: a pushdown stack.
What I wanted was a list of files in order by most recently accessed.
Unfortunately, it turns out that the app in question (my clone of TextEdit called DeskSpaceID), like many apps, maintains its Files > Open Recent files list in most recently opened order. Since the opening of the files is ancient history compared to when they were accessed, the Open Recent files list turned out to be useless for my purposes, and that list was obtainable by simpler means, if I needed it. (I certainly am not going to figure out how to change the app. It's built-in Apple stuff that is way beyond my pay grade.)
Creating the pushdown stack seemed daunting at first, and then turned out to be super easy. Here's the block from the subroutine that uses it:
This subroutine gets called by a macro that provides the newly accessed filename. If the global list does yet exist or is empty, that filename becomes the first item in the list.
If there already is a list, the list gets edited to delete the new filename from the list, if it's already there. Then the new filename gets added at the top of the list.
That's it. It's been working well for me for a couple of days, with lots of use.
I did run into a problem when the calling macro couldn't find the file and provided an error message instead of a file name. The error messages were unique, so the stack filled up with those, and they were never deleted because the older ones were never exactly replaced. I fixed the calling macro to not go here when there's an error.
Also, I made extensive use in fine-tuning this, including discovering the above error problem, by referring to the KBM > Preferences > Variables window. Selecting the global variable that is the stack made it easy to watch the stack change as it was used.
In the above image of the Variables window, there's an error message instead of a filename in the 10th entry. The Preferences: Variables window allows me to manually edit the variable and delete that line while I also fix the condition that produced it.