Applescript for moving recently added files (not created or modified) to another folder

applescriptfinderfolder-actionpdf

I would like to get a recent downloaded pdf file ( !: it corresponds to the Finder sort method Date Added, not Date Created nor Date Modified) and either just moving to one another folder (if using plain AppleScript) or ask the user to perform this action (if using FolderActions).

So the idea is to move some new downloaded pdf files to another location.

Is it possible with either AppleScript or with FolderActions or anyhow? Are there any examples for that?

Best Answer

The answer depends on what version of OSX you are running.

Snow Leopard doesn't appear to store Date Added or Creation Date of files.

$ stat -x testfile 
  File: "testfile"
  Size: 7            FileType: Regular File
  Mode: (0644/-rw-r--r--)         Uid: (  501/ vic)  Gid: (   20/   staff)
Device: 14,2   Inode: 12130091    Links: 1
Access: Mon May  5 21:49:18 2014
Modify: Mon May  5 21:49:15 2014
Change: Mon May  5 21:49:15 2014

For Lion and later, there are a couple of ways that Google revealed:

Try the following code taken from

https://discussions.apple.com/message/23974953#23974953

tell application "Finder"
    set latestFile to item 1 of (sort (get files of (path to downloads folder)) by creation date) as alias
    set fileName to latestFile's name
    log "Created/Added Date: " & (get creation date of latestFile)
end tell

Alternatively have a look at the code that uses the mdls command line tool as shown here

https://secure.macscripter.net/viewtopic.php?id=37910

Unfortunately I am running Snow Leopard and cannot test the above.