4 Replies Latest reply: Mar 3, 2013 8:37 PM by pjdube
Robm88 Level 1 Level 1 (0 points)
Hi, I was wondering if it is possible to use automator to automatically delete files in the download file after they have been sitting in there for a month or so? Your help would be greatly appreciated.

MacBook (black), Mac OS X (10.5.5), 2.16 GHZ processor, 2GB RAM
  • 1. Re: How to use automator to automatically delete files in the download fold
    V.K. Level 9 Level 9 (56,120 points)
    yes, it's possible but it will require a bit more than automator.

    First, copy and paste the following into script editor.

    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px;
    color: #000000;
    background-color: #ADD8E6;
    overflow: auto;"
    title="this text can be pasted into the Script Editor">
    on adding folder items to this_folder after receiving added_items
    tell application "Finder"
    repeat with this_item in added_items
    set ppath to POSIX path of this_item
    do shell script "touch " & quoted form of ppath

    end repeat
    end tell
    end adding folder items to
    </pre>


    save it as a script and add it to the folder homedirectory/library/scripts/Folder Action Scripts. Create it if it doesn't exist already. then add this script as a folder action on your downloads folder.

    Next, paste the following into script editor and save it as an application.

    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px;
    color: #000000;
    background-color: #ADD8E6;
    overflow: auto;"
    title="this text can be pasted into the Script Editor">
    tell application "Finder"
    delete (every item of folder (path to downloads folder) whose modification date is less than ((current date) - 30 * days))

    end tell</pre>

    Finally, download and install [lingon|http://tuppis.com/lingon> and make a launch daemon to run this application periodically (once a day should be good enough).
  • 2. Re: How to use automator to automatically delete files in the download fold
    spazek Level 2 Level 2 (215 points)
    This will work great, but let me notice two minor details:
    When starting using the folder action, you have to remove all the current excisting files in the download folder once (and move them back )
    Also it will work on files in that folder only, but not on files of any subfolders (if existing)

    Run the script as launchd is +the way+ on your Mac, but -in case you are afraid of using Lingon (it is great)- there is an alternativ way to run it periodically from iCal

    Spażek
  • 3. Re: How to use automator to automatically delete files in the download fold
    V.K. Level 9 Level 9 (56,120 points)
    thanks, spazek. those are good points. In particular, I didn't think about subfolders.
    as it's set up currently it will remove the entire subfolder after 30 days from the moment the subfolder is created. this seems more or less acceptable. frankly I don't know how to refine it to take into account age of individual items in the subfolders.
  • 4. Re: How to use automator to automatically delete files in the download folder
    pjdube Level 3 Level 3 (830 points)

    I know this is old. But Automator can do this too.

     

    Here is the workflow. Set it as an iCal Alarm and set the alarm to occur monthly and this should work.

     

    Good luck.

     

    http://f.cl.ly/items/1D3u100P0L2c2q1r0g2h/h.JPG

     

    Regards,

     

    Phil