A simple way to track your macbook using the isight

These instructions are for how to implement a simple laptop tracking script on any Mac laptop. With OS X > 10.5. All of the files for this can be found in the following github repository. Download the following:

  1. Get isight capture
  2. Get sleepwatcher

Download isightcapture and mount the image once the download is complete. Copy the ‘isightcapture’ executable to either /usr/sbin or /bin/ (I placed it into /bin). Download sleepwatcher to your Desktop and extract the archive. After it’s extracted, fire up terminal.app and enter the following:

$ sudo mkdir -p /usr/local/sbin /usr/local/share/man/man8
  $ sudo cp ~/Desktop/sleepwatcher_2.1.1/sleepwatcher /usr/local/sbin
  $ sudo cp ~/Desktop/sleepwatcher_2.1.1/sleepwatcher.8 /usr/local/share/man/man8

You'll then need to add a bash script to be executed when your laptop wakes. You'll want to save this file as /etc/rc.wakeup. You can use the following replacing the relevant parts:

#! /bin/sh

  date=$(date +%d%m%y%H%M%S).jpg;

  sleep 5;

  /bin/isightcapture -w 640 -h 480 -t jpg /Users/USERNAME/Photos/$date;

  sleep 60;

  cur_status=`ifconfig en0 | grep -o '[a-z]*active'`;
  cur_user=`id -un`;
  cur_host=`scutil --get LocalHostName`;

  if [ $cur_status == 'active' ]; then
      ip_string=`python /Users/USERNAME/Documents/get_geoip_data.py`
      ip_string="connection inactive";

  ip_log_string="$(date +%d/%m/%y' '%H:%M:%S), ${cur_host}, ${cur_user}, ${ip_string}";

  echo $ip_log_string >> /Users/USERNAME/Photos/IPLog.txt;

Don't forget to make sure that the rc.wakeup file has the appropriate read/write attributes. Once you've saved it in the appropriate directory, enter terminal, navigate to the directory the script is saved in and enter the following command:

$ sudo chmod 755 rc.wakeup

You'll notice that the ip is obtained by the 'get_geoip_data' python script. Create a file in the directory specified in the bash script, with the filename get_geoip_data.py and fill it with:

from BeautifulSoup import BeautifulSoup
  from urllib2 import urlopen

  def get_geoip_data():
      result = {}
      url_string = "http://www.maxmind.com/app/locate_my_ip"
      res = urlopen(url_string)
      html = res.read()
      soup = BeautifulSoup(html)
      keys = soup.findAll(attrs={'class' : 'tblProduct1'})
      values = soup.findAll(attrs={'class' : 'output'})
      for i in range(0, len(keys)):
          result[keys[i].contents[0].strip()] = values[i].contents[0].strip()
      return result

  def format_result():
      output = get_geoip_data()
      lat_lon = output['Latitude/Longitude'].split('/')
      ip = output['Your IP Address']
      print "%s, %s, %s" % (ip, lat_lon[0], lat_lon[1])


In order to use this script, you'll need to have the Beautiful Soup python package installed. If you have easy_install, you can install it with easy_install BeautifulSoup, or you can install it from source by going to the website

Finally, you need to set up the configuration file that is going to be handled by the LaunchDaemon. Create a file called sleepwatcher.plist and fill it with the following:

<?xml version="1.0" encoding="UTF-8"?>
  <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
  <plist version="1.0">
      <string>-w /etc/rc.wakeup</string>

You'll then need to copy the configuration file to /Library/LaunchDaemons/ and enable the LaunchDaemon by entering the following command:

$ launchctl load /Library/LaunchDaemons/sleepwatcher.plist

You should now be good to test that everything is working by closing the lid on your laptop and then reopening it. You should find a photo of your face in your photos directory. To make sure that you get the most value out of it make sure to use it with Dropbox and ensure your photos directory is being synced or alternatively, change the relevant directories in the bash script for the appropriate directory in your Dropbox folder.

For additional fun, you can sync these photos with your Facebook, Flickr or Picassa albums through their REST APIs, or use a different cloud storage solution so you can see who is using your device.

If you get stuck, feel free to email me.