As learned from google and sister stack sites, this is the working solution I've come up with for getting the path of latest added file in a folder. But this is not giving the accurate result. I'm using Mavericks (OS 10.9)
set myFolder to "/Users/lawsome/folder"
tell application "Finder" to set latestFile to the last item of (sort files of (POSIX file myFolder as alias) by creation date) as alias
set latestpath to POSIX path of latestFile
set latestpath to POSIX path of latestFile
Finally, Jose Alban's answer in here@askdiff gives an accurate sorted list using the mdls terminal command. How can I get the file path of last entry in this list.
Or any way to get the desired path.
Best Answer
The AppleScript code looks as thought it's getting the
creation date
rather than thedate added
. Finder and System Events don't storedate added
information in AppleScript. If you were running Yosemite, you could have done it with AppleScriptObjC. But, with Mavericks, the only avenue I can think of is by way of shell scripting.Via bash script:
From within an AppleScript:
AppleScript has the ability to execute shell commands using
do shell script
. You can either run the whole command above usingdo shell script
, which is probably what most people would do. But, just for demonstration purposes, I'm going to mix it with a bit of AppleScripting too.