Example: Writing a Launch Agent for Apple's launchd
Clutter in programmer workspaces, whether digital or physical, add a mental
cost. An area of common clutter is the
~/Downloads directory in Mac OS X.
I want to clean it up... programmatically.
I want a background job to find files in
~/Downloads which haven't been
modified within the past week and move them into
~/.Trash. In zsh, we do:
mv ~/Downloads/*(mw+1) ~/.Trash
man zshexpn for more awesomeness on shell expansion.
For a user-specific background job, Apple recomends creating a Launch
Agent, which is a
file located in
~/Library/LaunchAgents/com.thoughtbot.cleandownloads.plist will run my
script once an hour:
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
Label com.thoughtbot.cleandownloads ProgramArguments mv ~/Downloads/*(mw+1) ~/.Trash StartCalendarInterval Hour 1
Read Creating Launch Daemons and
Agents for more on
how to structure the
Ain't nobody dope as me, my Downloads directory is so fresh and so clean clean.