Your Mac Knows When You're Home
Pages: 1, 2

Preparing Proximity

Next, open the Proximity application on your Mac. Choose Preferences from the Proximity menu item in your menu bar (look towards the right end of the menu bar to find it), then do the following:



  1. In the General tab, check Monitoring and enter how often you want Proximity to check for the presence of your Bluetooth device. Choose a scan interval that makes sense for your situation. For example, if you want your Mac to turn on the room lights as soon as it detects your presence, you'll want to have Proximity look for your cell phone every minute or so. But if you simply want to adjust your automated thermostat, or to announce how many mails you have waiting, then a scan interval of every 10 minutes might be sufficient.
  2. In the Device tab, click Change Device then select the Bluetooth device that you paired with your Mac in the earlier set up steps, as shown in Figure 1.
  3. Figure 1
    Figure 1. Proximity watches for a Bluetooth equipped device, then runs a script when it finds it nearby.

  4. When you're done, click Check Connectivity to make sure that Proximity is able to detect your device.
  5. In the Scripts tab, select an "In Range Script". The script is executed when Proximity detects that your device, and by inference, you, are within range of your Mac. We'll discuss the script in more detail soon.

Proximity can also execute a script when it stops detecting your device, which you configure with the "Out of Range Script" option, but I haven't found this useful for home automation. The reason is that Bluetooth's range is rather limited, so you can't reliably infer that you've left home simply because your device has moved out of range. You might have only gone to the kitchen for another cup of coffee.

Instead of using Bluetooth to guess when I'm gone, I manually tell my home automation system that I have left. This is nearly automatic for me because my home alarm system sends a signal to XTension when I turn it on. But, before I had the alarm system, I accomplished the same thing using an AppleScript that was triggered by pushing a button on a remote control I kept near the front door.

Putting it in Action

The AppleScript that you specified in Proximity is where all the magic happens, and here is your opportunity to really get creative. Anything you can accomplish with AppleScript you can have automatically done when you, carrying your Bluetooth device, get within sensing range of your Mac.

Figure 2
Figure 2. AppleScript lights your way home and tells you what you missed while you were out.

My Proximity script is shown in Figure 2. It performs several actions in sequence, some of which use conditions that are tracked for me by XTension. The first thing that happens is that the current time is after sunset, a lamp in the entryway is turned on. Not only is this welcoming, it provides a subtle visual cue that my Mac has recognized me and has started the script.

Next, the Mac uses text-to-speech to tell me how many phone calls I missed while I was gone. This information is tracked by XTension using PhoneValet ($169.96) to monitor incoming calls. The extra spaces before words that you see in the sayString variable are necessary to allow text-to-speech to correctly read the assembled message after the variables are substituted. If you accidentally leave the spaces out, parts of your messages will be spelled letter-by-letter instead of spoken.

Then, finally, the Mac announces how many unread email messages I have waiting. It determines this by asking Mail for the contents of a mailbox that only contains messages sent to me by people that I've assigned to a group in Address Book. This is accomplished by a rule that I have defined in Mail. These are all standard techniques but, as with much of home automation, it's the ability to connect existing pieces in new and convenient ways that creates value and adds convenience.

Doing What You Want

Now that you know to trigger actions automatically, the hard part is deciding on the most useful things to have happen. Perhaps you want to have Safari load your favorite web sites, or you could have appointments read from iCal. It's also good to think about the other people who share your home, perhaps the script should do something different if their cell phone is detected, too. The limit is your imagination, AppleScript ability, and the fun you find in experimenting with different approaches.