Hey Shane,
On Feb 09, 2012, at 16:15, Shane Stanley wrote:
That's much better, but you left out the "as alias" after set contents of i to (folderAlias & contents of i).
Hmm. You're right. I think I did that intentionally to allow choice in how to process the string, but I forgot to rename the variables. (Not sure; I've slept since then.)
And when you put it in, you get an error if any filename contains a slash. So I'd use:
set itemList to (do shell script "ls -tr " & posixFolderQuoted & " | tr ':' '/'")
Sure enough. Well, we might as well use the shell a bit more:
------------------------------------------------------------------------------------------------
on listFolderByModDate(folderAlias, returnAliasList)
set posixFolder to POSIX path of folderAlias
set posixFolderQuoted to quoted form of posixFolder
set hfsPathList to (do shell script "ls -tr " & posixFolderQuoted & " | sed \"s|:|/|g;s|^|" & (folderAlias as string) & "|\"")
if returnAliasList = true then
set aliasList to (paragraphs of hfsPathList)
repeat with i in aliasList
set theItem to contents of i
set (contents of i) to (alias theItem)
end repeat
return aliasList
else
return hfsPathList
end if
end listFolderByModDate
------------------------------------------------------------------------------------------------
try
tell application "Finder"
set folderAlias to target of front window as alias
end tell
set sortedItemList to listFolderByModDate(folderAlias, true)
on error eMsg number eNum
set {c, s} to {return, "------------------------------------------"}
set e to s & c & "Error: " & eMsg & c & s & c & "Error_Num: " & eNum & c & s
beep
display dialog e
end try
------------------------------------------------------------------------------------------------
This runs in ~ 0.6 seconds on a 1600 item folder on my machine when converting to aliases.
When returning HFS paths it runs in ~ 0.13 seconds on the same folder.