Le 10 févr. 2012 à 11:50, Christopher Stone a écrit :
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.
-- Best Regards,
Thanks for this code.Just a question :
I added a R in the call to Shell to get the contents of subfolders.
So the instruction became :
set hfsPathList to (do shell script "ls -Rtr " & posixFolderQuoted & " | sed \"s|:|/|g;s|^|" & (folderAlias as string) & "|\"")
When I run it, I get this 'surprising' result :
Macintosh HD:Library:Fonts:/Library/Fonts//alba ƒ/ Macintosh HD:Library:Fonts:Icon Macintosh HD:Library:Fonts:Alba Macintosh HD:Library:Fonts:Alba Matter Macintosh HD:Library:Fonts:Alba Super Macintosh HD:Library:Fonts:Read Me Please Macintosh HD:Library:Fonts:fonts.list Macintosh HD:Library:Fonts:fonts.scale Macintosh HD:Library:Fonts:fonts.dir Macintosh HD:Library:Fonts:encodings.dir Macintosh HD:Library:Fonts: Macintosh HD:Library:Fonts:/Library/Fonts//Century Gothic ƒ/ Macintosh HD:Library:Fonts:Century Gothic.ttf Macintosh HD:Library:Fonts:Century Gothic.zip Macintosh HD:Library:Fonts:fonts.list Macintosh HD:Library:Fonts:fonts.scale Macintosh HD:Library:Fonts:encodings.dir Macintosh HD:Library:Fonts:fonts.dir Macintosh HD:Library:Fonts: Macintosh HD:Library:Fonts:/Library/Fonts//Caviar-Dreams ƒ/ Macintosh HD:Library:Fonts:CaviarDreams_Bold.ttf Macintosh HD:Library:Fonts:CaviarDreams.ttf Macintosh HD:Library:Fonts:CaviarDreams_BoldItalic.ttf Macintosh HD:Library:Fonts:CaviarDreamsItalic.ttf Macintosh HD:Library:Fonts:Nymphont License.txt Macintosh HD:Library:Fonts:fonts.list Macintosh HD:Library:Fonts:fonts.scale Macintosh HD:Library:Fonts:encodings.dir Macintosh HD:Library:Fonts:fonts.dir Macintosh HD:Library:Fonts: Macintosh HD:Library:Fonts:/Library/Fonts//Caslon Antique ƒ/ Macintosh HD:Library:Fonts:Caslon Antique Italic Regular Macintosh HD:Library:Fonts:Caslon Antique Regular Macintosh HD:Library:Fonts:fonts.list Macintosh HD:Library:Fonts:fonts.scale Macintosh HD:Library:Fonts:encodings.dir Macintosh HD:Library:Fonts:fonts.dir Macintosh HD:Library:Fonts: Macintosh HD:Library:Fonts:/Library/Fonts//Candela ƒ/ Macintosh HD:Library:Fonts:LicenseExtrasCandela.pdf Macintosh HD:Library:Fonts:CandelaItalic.otf Macintosh HD:Library:Fonts:CandelaBook.otf Macintosh HD:Library:Fonts:CandelaBoldItalic.otf Macintosh HD:Library:Fonts:CandelaBold.otf Macintosh HD:Library:Fonts:La Tipomatika License.txt Macintosh HD:Library:Fonts:fonts.list Macintosh HD:Library:Fonts:fonts.scale Macintosh HD:Library:Fonts:encodings.dir Macintosh HD:Library:Fonts:fonts.dir Macintosh HD:Library:Fonts:
The strings with slashes are the pathq to subfolders Below are the paths to files embedded in the subfolder but the 'subfolder' descriptor is dropped.
Macintosh HD:Library:Fonts:LicenseExtrasCandela.pdf would be : Macintosh HD:Library:Fonts:Candela ƒ:LicenseExtrasCandela.pdf
Yvan KOENIG (VALLAURIS, France) vendredi 10 février 2012 12:32:18
|