If you’re anything like me (which you are probably thankfully not) you have a dream. A dream that you make all of your friends listen to you endlessly discussing in the pub. A dream that has long ago ceased being based in logic or sense, but is now just something you have to achieve if only to make up for never shutting up about it.
My dream, was to have my doorbell tweet me when someone rang it. Not much of a dream, I’ll admit, but still something I wanted. Before I got my iPhone I used BluePhone Elite with every phone I had (the iPhone doesn’t support the best bits, though). Aside from the main benefits such as texting and answering the phone from my mac, it also alerted me when my phone was ringing and who was calling. This was very unexpectedly useful – often my phone would be on silent and in the pocket of my jacket somewhere, and I would know firstly that it was ringing at all, and secondly whether or not it was worth answering. It solved a problem I didn’t realise I had.
I decided at this point, that everything in my house must be able to send me notifications. Preferably Growl notifications. If you don’t know what Growl is, follow that link and then come back. We’ll wait.
Recently I got a new front door put in. Part of the deal was a Yale “Electronic Door Viewer” which I got cheap since I get on well with the builder that fitted it. It consists of a small box, and a camera that looks like a regular spyhole – except it also has a doorbell button underneath. This little box and camera, both play doorbell chimes and display a picture of the person ringing the bell on a small (poor quality, but good enough) screen. What pleased me most though, was that the pictures are stored with a date/time stamp on an SD card inside the box, so that I can see who rang the bell at what time when I return home. There are a few issues with the setup… people seem to have difficulty locating the bell even with a sticker underneath it saying “this is the doorbell”, the LED lights that light up when the bell are rung blind people, very short people appear to be invisible and I never remember to check the box for pictures when I get home (much like when my phone answering machine became a phone-based service instead of hardware – with no blinking light, I don’t realise I have a message and forget to check). I can’t do much about some of these issues. People can’t find the bell – I might make another, bigger sticker. I will stick some kind of filter over the LED lights to save me from lawsuits. Short people will just have to remain invisible. But forgetting to check the box for new pictures, this seemed impossible to overcome.
Then I came across the Eye-Fi range of SD cards. These have an 802.11n wireless network adapter – built-in. I have no idea how they do that. But they do. The smallest was 4GB, which is excessive for my plans, but that was the smallest. I bought one from Amazon for £50 with free delivery.
Setting up the Eye-Fi card is really easy. It comes with a USB adapter and the software worked fine and was reasonably intuitive. Whenever the card has power and it can find one of the wifi networks you have setup on it with USB it automatically transfers any images (or videos) stored upon it to your mac/PC. I was worried that the doorbell wouldn’t keep power to the card for long enough to make the transfer, but the default setting of 20 seconds or so is apparently enough time to set up a network connection and copy the file across. You can set it up to automatically post them to Facebook or Flickr (or various other services), but that wasn’t what I wanted to achieve. To get the pictures to Twitter was going to take a few extra steps.
As a quick note, I am not 100% sure of the legal position of posting pictures of people on the Internet without their permission. Since it says “CCTV Recording In Operation” above the camera, and the people are outside in plain view, I am pretty sure I’m okay – but I wouldn’t want you to cite me as the person that gave you the go ahead to do this. So if you’re not sure, find out.
So, now the Eye-Fi was automatically putting pictures in a folder (I think
~/Pictures/EyeFi/). It was also adding date information to the folder structure, so in the Eye-Fi software settings I changed this to just stick them all in the root of the directory that was set. OS X has something built-in called “Folder Actions” which allows it to react to changes to a folder. Normally you just locate the folder, right-click it (or control-click for you really old school people) and choose “Folder Actions Setup…”. For some reason, that wasn’t working on my machine so I had to locate the app manually at
/System/Library/CoreServices/Folder Actions Setup.app. Until you have a script written though, there’s not yet much you can do except use the provided scripts which are no good to me. So, I started writing the AppleScript. First I needed to be able to send direct messages. Using curl, this is pretty easy:
on dm(user, pwd, recipient, msg)
do shell script ("curl -k -u " & user & ":" & pwd & " -d 'text=" & msg & "&user=" & recipient & "' https://twitter.com/direct_messages/new.xml")
Posting a picture online was a bit trickier. For the time being I have used TwitPic but this seems a bit open for my liking. I may revisit that in the future. So, I created another Twitter account (set to private) and made that and my normal account follow each other so they were able to send direct messages to each other. Then I created this script to post images to TwitPic:
on twitpic(filepath, user, pwd)
set scriptpath to "curl -k -F media=@" & filepath & " -F username=" & user & " -F password=" & pwd & " -F message= https://twitpic.com/api/upload"
set xmlValue to (do shell script scriptpath)
--Parse the result for whether the upload was successful
if xmlValue contains "<rsp stat="ok">" then
tell application "System Events"
set xmlData to make new XML data with data xmlValue
set URI to value of (XML element "mediaurl" of XML element "rsp" of xmlData)
display dialog "TWITPIC ERROR " & xmlResponse as string
It’s not the most bug resistant code in the world, but it will at least show an error message on the machine if it fails, saying (hopefully) why it failed.
Finally, I needed to hook these altogether. I added to my fast growing script:
on adding folder items to this_folder after receiving added_items
set twitteruser to "twitteruser" --amend this to be the user name of your doorbell
set twitterpwd to "password" --amend this to be the password of your doorbell
repeat with itemadded in added_items
set the item_path to quoted form of the POSIX path of itemadded
set mediauri to postPicture(item_path, twitteruser, twitterpwd)
sendDirectMessage(twitteruser, twitterpwd, "username", mediauri as string) --amend this to be the username you want to be alerted. Duplicate the line if you want to alert more users.
end adding folder items to
I saved this as
Macintosh HD/Library/Scripts/Folder Action Scripts/. Now I was ready to open up the
Folder Actions Setup… again. I located the folder Eye-Fi was downloading into (uploading to? Whatever), right clicked it, and chose
Folder Actions Setup…. I selected
eyefi.scpt from the list, and made sure that the right folder was in the left-hand column, and that
Enable Folder Actions was ticked. Finally, I pressed the doorbell (while ducking out of the way like a coward). Success! I received a direct message with this attached:
I also received an email about it, since it was a direct message and I have Twitter configured that way. I was living the dream! Perhaps a shallow, superficial, superfluous and ridiculous dream, but the dream nonetheless.
My next job is to make it send Growl notifications.
I hope you love this as much as I do, and if not, keep it to yourself. What do you think? How could I make this more epic? Let me know in the comments.
Update: I now have growl notifications working too! Read about that here.