El AppleScript código es como el pensamiento es llegar a la creation date
más que el date added
. Buscador y los Eventos del Sistema que no almacene date added
información en AppleScript. Si se Yosemite, usted podría haber hecho con AppleScriptObjC. Pero, con Mavericks, la única vía que se me ocurre es por la manera de shell scripting.
A través de un script de bash:
F=~/folder \
&& [[ -d "$F" ]] \
&& mdls -name kMDItemFSName -name kMDItemDateAdded -raw "$F"/* \
| xargs -0 -I {} echo {} \
| paste -sd" \n" - - \
| sort \
| tail -1 \
| cut -f4- -d" " \
| printf '%s\n' "$F/$(cat)"
Desde dentro de un AppleScript:
AppleScript tiene la capacidad de ejecutar comandos de shell usando do shell script
. Puede ejecutar el comando completo sobre el uso de do shell script
, que es probablemente lo que la mayoría de la gente haría. Pero, sólo para fines de demostración, voy a mezclar con un poco de AppleScripting demasiado.
property text item delimiters : space
set myFolder to "/Users/lawsome/folder" -- Folder to be evaluated
-- Assemble shell command
set sh to the contents of {¬
"[[ -d", quoted form of myFolder, "]]", "&&", ¬
"mdls", "-name kMDItemFSName", "-name kMDItemDateAdded", ¬
"-raw", [quoted form of myFolder, "/*"], ¬
"|", "xargs", "-0 -I {} echo {}", ¬
"|", "paste", "-sd' \\n' - -", ¬
"|", "sort"} as text
do shell script sh -- run the bash command
set latestFileAddedToFolder to the last paragraph of the result
--> e.g. 2018-08-13 08:02:52 +0000 Some File Name.txt
-- Split text up into date components and filename text
set [{yyyy, m, dd, HH, MM, SS, "+", timezone}, filename] to ¬
[words 1 thru 8, text 27 thru -1] of latestFileAddedToFolder
-- Construct AppleScript date object from date components
tell the (current date) to set ¬
[dateAdded, year, its month, day, time] to ¬
[it, yyyy, m, dd, hours * HH + minutes * MM + SS]
set pathToMostRecentlyAddedFile to myFolder & "/" & filename
return contents of {pathToMostRecentlyAddedFile, ¬
"was added to its containing folder", myFolder, ¬
"on", date string of dateAdded, ¬
"at", time string of dateAdded} as text