HOWTO: Track your mac
A couple years ago, after I purchased a mac laptop with a built-in camera, I set it up to take a picture every time it booted/woke up and upload it to one of my web servers if internet access was available. I called it my poor man’s laptop lojack. Of course with all good things, Apple came out with an operating system update that disabled access to the camera from any user (even root) except for the locally logged in user. I suppose that is a good thing except when you actually *want* to be able to do what I was doing. Once it broke, I hadn’t bothered to figure out a way around it until the other night when I was pissed off enough to find a way!
Luckily, a couple weeks ago, I learned about launchctl. It is now the primary way in OSX to launch system daemons instead of init scripts or xinetd. It turns out, using launchctl, as root, you can execute a program in another context using its bsexec subcommand! If you use the loginwindow process id’s context you’d like to run your program in, it will now run just as if you were physically sitting at the keyboard. The command:
isightcapture image.jpg
which would before fail if you ssh’d into a remote machine now becomes:
export PID=`ps auxww |grep loginwindow |grep -v grep |awk ‘{print $2}’`
launchctl bsexec $PID isightcapture image.jpg
Bamo! Now you’re breakin’ the law in style!
So, since I’ve got my crappy little image uploader working once again, I thought I’d share it with the rest of the world. I’m using sleepwatcher, isightcapture, and some other craziness that I hacked together to overlay some good information on a picture from your webcam and upload it to a website of your choice!
If you know what you’re doing, you should be able to follow my instructions just fine, if you don’t know what you’re doing, you might possibly blow up your mac and kill a kitten. You have been warned!
First, download the following file (I’m going to assume it will download into your Downloads folder):
http://tompohl.com/files/locateme.tgz
Create a directory on your web server to host the supporting scripts and uploaded images for example:
mkdir /var/www/html/locateme
mkdir /var/www/etc
htpasswd -c /var/www/etc/locateme.passwd myuser
htpasswd /var/www/etc/locateme.passwd anotheruser
<Directory “/var/www/html/locateme”>AuthType BasicAuthName PrivateAuthUserFile /var/www/etc/locateme.passwdAllowOverride NoneOrder allow,denyAllow from allrequire valid-user</Directory>
apachectl configtest
apachectl graceful
cd ~/Downloadstar -xzvf locateme.tgzcd locatememv .locateme /
chmod 777 /var/www/html/locateme/uploads
sudo vi /etc/rc.wakeup
su – $user -c “$home/.wakeup”
$home/.wakeup
ln -s /.locateme/.wakeup ~/.wakeup
vi /.locateme/locateme.conf
- If your computer doesn’t connect to the network, it will still save your pictures in /.locateme/images/taken and all images successfully sent to the webserver will be moved into /.locateme/images/sent
- On the webserver, all images will be saved in the directory locateme/username/ with locateme/username/latest.jpg always pointing to the last picture taken.
isightcapture:http://www.intergalactic.de/pages/iSight.html
sleepwatcher:http://www.bernhard-baehr.de/







Clever trick. There's no gps built into the computer but somehow my phone is able to grab remarkably accurate coordinates using wifi. Maybe tagging the image w/ current location would be a nice enhancement.
Of course when my wife's phone got stolen I was able to track it's location just fine and yet I still had to buy a new phone.
If you look through my server-side code, you'll see that I make a call out to api.hostip.info to get a rough idea of where the machine is based upon source ip. It is fairly accurate. I was debating about using a service that returned the gps coordinates, but didn't think it would be very accurate because it wasn't taking into consideration BSSIDs of networks physically near by like the iphone or ipod does!
i cannot get this to work on my SL?
Which part do you think isn't working? Does it take pictures and place them in /.locateme/images (either its send or taken subfolder)? You won't be able to browse to the /.locateme folder directly from Finder since it is a hidden folder, but you can get there by choosing "Go"->"Go to Folder …" from the menu in Finder.