Life and code.
RSS icon Home icon
  • How To Automatically Clean Your macOS Downloads Folder

    Posted on March 27th, 2017 Brian No comments

    I download a lot of crap, and it ends up in my Downloads folder. I used to use Hazel to keep my Downloads and Trash clean, but it was overkill: Hazel is a much more powerful tool than I needed. With the relatively recent addition to macOS to automatically remove items from the trash after 30 days I was left with just my downloads folder.

    So I wrote a script.

    #!/usr/bin/env bash
    find "$folderName" -type f -ctime "+${olderThan}" -not -name '.*' -exec rm '{}' ';'
    find "$folderName" -type d -empty -not -name '.*' -exec rmdir '{}' ';'

    Then, I installed it as a regularly-running launchd agent.

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
    <plist version="1.0">

    Which I then copied to ~/Library/LaunchAgents/net.ardvaark.autocleandownloads.plist, and installed with the command:

    launchctl load ~/Library/LaunchAgents/net.ardvaark.autocleandownloads.plist

    And now my Mac automatically cleans my download folder of anything older than a week every morning at three o’clock.

    Comments are closed.