If you have a Mac, you probably have an iPhone. With Airlock, you can use your iPhone to automatically lock and unlock your Mac when you are away.
Airlock uses Bluetooth to tell your computer when you leave the room (or other proximity; you can change the settings). When you leave, your computer is locked by Airlock. When you return, Airlock will wirelessly tell your computer you are back, and unlock your computer.
You can also program Airlock to tell your computer to run various programs upon your return. If you lose your iPhone, or the battery dies, you can still use a manual login function, so you are not left in the lurch.
Unfortunately, Airlock can cause minor problems if you use a wireless keyboard or mouse. Because of a Bluetooth firmware issue, Airlock can cause your mouth or keyboard to disconnect. Apple is apparently working on a firmware update to correct this.
There are other ways to have your computer automatically lock, such as making a hot corner that puts your computer to sleep, or setting up your screensaver to come on after five minutes of inactivity. Airlock, however, seems to be the easiest, and quickest option.