Before I answer the question you asked, I’m going to guess that you are trying to get the logfile of the last run of a script. There’s a pretty simple way of doing that:
put file (the logFile of the last item of scriptResults("someScript"))
The scriptResults function returns a list of property lists, one for each run of the specified script. They’re returned in date order, so the last one in the list is the most recent run. One of the properties of the property list is the logfile, which is the full path to the logfile.txt.
If you need to do this in some other directory, then this code should work for you:
put the folders of "~/documents" into folderList
sort folderList chronologically by the NSFileModificationDate of each
put the last item of folderList
The folders() function returns a list of file/folder objects, each of which has a number of properties, one of which is the modification date. If you just output one of the items in the list, it returns its description, which is just its name, but if you ask for something like “the keys of the last item of folderList” then you’ll see all of the properties recorded for that folder.