scripts / bash / research

Reading time:
2 min. | 418 words

Here’s a few nerdy bits I’ve been working on lately in my free time – just a few scripts that I’ve been using to take care of things on my Mac automatically.

The first is a one-line bash script that will automatically delete items from my Downloads folder that are more than a week old:


find /Users/hepplerj/Downloads/* -mtime +7 -exec rm -rf {} \;

The only additional change I want to make to the script is to log what was deleted to a text file, but I’ll work on that on another evening. I automate the script using launchd (the OS X version of cron). You can copy the code to a file called com.yourusername.cleandownloads.plist and save it under ~/Library/LaunchAgents/. You’ll either need to log out and log back in, or run launchctl load ~/Library/LaunchAgents/com.yourusername.cleandownloads.plist to get it started. The code as set up here will run at 11:50pm every Saturday night:

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

Perhaps not as elegant as cron, but it gets the job done.

I don’t know if anyone will find this useful, but it’s a nice method for me. I never remember (nor enjoy) having to comb through my Downloads. This will move everything to the Trash every week for me without having to think about it. It also puts something in the back of my mind that forces me to address a download immediately (e.g., if it’s a PDF of an article I intend to keep it needs to get filed) rather than have it sit in the folder indefinitely. The next step I want to figure out is to have the Trash empty automatically.

The other script I’m loving lately is drawn from the incomparable Brett Terpstra. Borrowing from Brett, I’ve added a command to my .bash_profile that allows me to log git commits to a text file. The script looks like this:

# wrapper for git to log commits to an nvALT note
# just an overall reminder of what I did all night
function ca(){
  before=$(cat "$note")
  echo "$(date '+%y-%m-%d %H:%M | ') (${path##*/}) $msg" > "$note"
  echo "$before" >> "$note"
  git commit -am "$msg"

I send the log to my notes folder in Dropbox, which is the same directory that is indexed by nvALT. So, whenever I’m doing a new commit to git, I can just write ca ‘Here is my commit message’, hit return, git will do its business and copy the commit message to the text file. A simple task, but a nice record of things I’ve completed for different projects.


Greetings! My name is Jason Heppler. I am a Digital Engagement Librarian and Assistant Professor of History at the University of Nebraska at Omaha and a scholar of the twentieth-century United States. I often write here about the history of the North American West, technology, the environment, politics, culture, and coffee. You can follow me on Twitter, or learn more about me.