A Few New Scripts
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:
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:
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:
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.