Skip navigation

How to use automator to automatically delete files in the download folder

1956 Views 4 Replies Latest reply: Mar 3, 2013 8:37 PM by pjdube RSS
Robm88 Calculating status...
Currently Being Moderated
Sep 23, 2008 12:38 PM
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
  • 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).
    Mac Pro 3.2 GHz, Mac OS X (10.5.5), Mac Pro 2.66GHz, powerbook G4 1.5GHz
  • 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
    MBP, Mac OS X (10.5.5)
  • 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.
    Mac Pro 3.2 GHz, Mac OS X (10.5.5), Mac Pro 2.66GHz, powerbook G4 1.5GHz
  • 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

Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.