# Automator: Filter Finder Items selecting wrong files

The workflow looks like this:

When I test it, it works fine - selecting only files older than 60 days. However when I actually download a new file to the downloads folder it sends the new file to the trash.

What gives? Is the timestamp on the new file not correct until after the download finishes or something?

EDIT: I discovered that it deletes the file being added to the folder no matter what. Meaning - if I drag and drop a new file to the folder, the workflow deletes it even though the time stamp is from today.

• As an example, as a file is being downloaded in Safari, it has a .download extension appended and a date/time stamp of 01/24/1984 3:00 AM (at least on the East coast of the US). So, I'd try setting the Filter Finder Items action to | Find file where: All of the following are true | File extension is not .download | Date last opened is not in the last 60 days | and see if that makes any difference for you. – user3439894 Sep 6 '17 at 15:30

Here is a solution to bypass Automator completely. Just save this script in the Script Editor.App to your /Users/your_shortname/Library/Workflows/Applications/Folder Actions folder. Once you do that, that folder action script will be available to choose from in your Services/Folder Acions Setup menu in Finder by control + click the downloads folder

This is the version if you are going to use Script Editor.app

on adding folder items to this_folder after receiving these_items
tell application "Finder"
set deleteFilez to items of (path to downloads folder) whose creation date < ((current date) - (days * 60)) and (name extension) is not in nameExtensionz
delete deleteFilez
end tell


If you do not feel comfortable with Script Editor app, in Automator app you can add a run AppleScript action and add my code. Just view the screenshot below. You will not need to worry about the new downloaded file getting deleted

This is the version to use if you are going to add an AppleScript action to an Automator Workflow folder action

tell application "Finder"
set deleteFilez to items of (path to downloads folder) whose creation date < ((current date) - (days * 60)) and (name extension) is not in nameExtensionz
delete deleteFilez
end tell


• While this is a perfectly valid solution, the answer to "Why not?" is pretty simple: because we can't all write AppleScript, and that's the whole point of Automator ;) – calum_b Sep 6 '17 at 16:55
• Based on grgarside's answer, isn't this going to delete the file while it's downloading? (I haven't done any testing.) – user3439894 Sep 6 '17 at 17:16
• Just tested on Google Chrome and it waits until the download is finished. Works like a charm – wch1zpink Sep 6 '17 at 18:16
• @user3439894 My original code did not work using Safari. I just updated the code in my script and now it will not delete active downloading files. Now this works in Chrome and Safari – wch1zpink Sep 6 '17 at 20:17
• Your script works like a charm. I wish I knew exactly which automator action was going awry in my original attempt. The fact that I had a pause at the top of the script should have prevented it from deleting files as they were being created and waited until after the file existed to check its creation date. – Paul Wieland Sep 7 '17 at 20:43

Finder uses the kMagicBusyCreationDate for files currently being downloaded, which is 08:34:56 on 1946-02-14 (+0000).

Use this date as a file's or folder's creation date to indicate that it is temporarily busy (while it is being downloaded or installed, for example).

What is the significance of 1946-02-14 08:34:56?

As this is well outside your date range, the file is removed immediately. Therefore you can’t use any date based checks whilst files are being downloaded.

• I think this is the first time I've followed a link in a question to another question where I've ended up, up voting the question with the link as well as the linked question and its accepted answer. It was interesting reading! – user3439894 Sep 6 '17 at 17:12
• @user Thanks, that question was the first time I made hot network questions on SE! – grg Sep 6 '17 at 17:14
• @grgarside I just tested again by dragging and dropping a newly created file from my desktop to my downloads folder. The automator script deletes it even though the creation date is from today. – Paul Wieland Sep 6 '17 at 18:33
• @Paul The creation date whilst the file is being transferred is set to this too, so it’ll get deleted. ‘when copying or moving a file or folder using Finder; whilst the operation is in progress the destination file/folder is shown in grey. Finder is aware […] currently in an operation by setting the creation date of the file or folder to the kMagicBusyCreationDate’ – grg Sep 6 '17 at 18:52
• @grgarside Okay - so I added a "Pause" command as the first step in the automator flow and have it pausing for 30 seconds (more than enough time for the copy operation to complete, its only a 1kb txt file). It's still deleting it. Not trying to be a pain, but this is really strange to me! – Paul Wieland Sep 6 '17 at 18:55