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?

3 Answers 3


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


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


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


Finder and System Events file objects only have date modified and date created properties as of 10.9.

You might use mdfind instead:

mdfind -onlyin ~/Downloads 'kMDItemDateAdded>$time.now(-86400)&&kMDItemFSName="*.pdf"c'|while read f;do mv "$f" ~/Desktop;done


AppleScript - Remove Files Added 5 Minutes Ago

Elaborating on Lri’s answer, you could create a script that takes files that were downloaded 5 minutes ago and move them to the trash with a script like this (using Date Added sorting in Finder):

set dirSel to path to downloads folder
set timeInterval to -5 * 60 -- 1 measured in milliseconds e.g. -1*60 = 1 minute ago
-- 5 minutes ago = -5 * 60
set filteredList to {}
-- Get current user's name
tell application "System Events"
    set currentUser to (name of current user)
end tell

-- Check downloads folder and move files to the trash that are older than N minutes.
set locateDateAdded to "mdfind -onlyin " & quoted form of POSIX path of dirSel & " 'kMDItemDateAdded>$time.now(" & timeInterval & ")&&kMDItemFSName=\"*.*\"c'"
set filteredItemsOutput to do shell script locateDateAdded

tell application "Finder"
    repeat with itemStep from 1 to count of paragraphs of filteredItemsOutput
        set thisItem to paragraph itemStep of filteredItemsOutput
        set end of filteredList to POSIX file thisItem as alias
    end repeat
end tell

if (count of filteredList) is greater than 0 then
    tell application "Finder"
        display dialog "Would you like to move " & (count of filteredList) & " items to the trash?" & "
" & filteredItemsOutput
            delete every item of filteredList
        end try
    end tell
    display dialog "No files meeting the criteria were found."
end if

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .