Remotely Control Your Mac without a Computer
Volume Number: 23 (2007)
Issue Number: 04
Column Tag: Remote Control
Remotely Control Your Mac without a Computer
Use the world, and your location, to control and manipulate your home
By Andrew Turner
Introduction
If you are reading this magazine, you're probably like me and spend a large amount of time in front of your computer. You are very accustomed to using the keyboard, mouse/trackpad/trackball, and monitor to view and access your files and applications. In previous articles (January '07, February '07) we designed and assembled a location automation system that allowed your Mac to reach into the world and control it to turn lights on and off, make coffee, and control your stereo.
The system was designed such that you were sitting at your computer, or at another computer. It did not know if you were there, or know how to notify you of its status in the case of a problem. This article will lead you through a variety of tools and techniques you can use to remotely control your Mac and automation system based on the your location or the presence of your family or others. In addition, we will teach you how to have your computer let you know its status via remote communications such as email, SMS, instant message, or even a phone call.
This article assumes you are already familiar with Applescript and know how to use Script Editor. An automation software system like XTension or Indigo are not required for any of these techniques, but they can make the tracking and notification systems more useful and integrated into your environment.
Are you Here?
Currently, your computer probably only knows that you come home or arrive to the office when you first move the mouse or press a key. By this time it has to wake up the monitor and start up your programs. Perhaps it also starts up some music to soothe you. When you leave, you manually log out of your email and chat programs (or at least change your status message).
Wouldn't it be easier if your computer would know when you have arrived (or left) without you physically interacting with it?
Using a mobile device
Your mobile phone and PDA are constantly sending out signals looking for devices to pair with via BlueTooth or WiFi (802.11). Presumably, you also carry your device with you as you come and go. Therefore, it can be used for detecting your proximity to your computer.
Salling Clicker (http://www.salling.com) is an application that detects your mobile devices' Bluetooth or WiFi proximity and can then execute commands or Applescript. For example, when you first arrive at your computer, you can have iChat open, change your status to Available, set a state variable, turn on your desk lamp, and start playing music:
using terms from application "SEC Helper"
on process entering proximity a_terminal
my set_ichat_status({a_text:available_message, a_status:true})
tell application "iTunes" to play
tell application "IndigoServer"
turn on "Desk Lamp"
set value of variable "Andrew_Here" to "true"
end tell
end process entering proximity
on process leaving proximity a_terminal
my set_ichat_status({a_text:away_message, a_status:false})
tell application "iTunes" to pause
tell application "IndigoServer"
turn off "Desk Lamp"
set value of variable "Andrew_Here" to "true"
end tell
end process leaving proximity
end using terms from
In practice, you could set up an Action Group or Trigger Action in Indigo to perform more complex commands and operations and call those from the proximity script. Additionally, there are functions available for setting your status in other applications such as Adium and Skype. Blue Phone Elite (http://mirasoftware.com/BPE/) is another application that has programmed proximity behaviors and many other unique features, but has a shorter list of compatible devices and only works with Bluetooth.
While using Bluetooth or WiFi devices to track our proximity has a high 'wow' factor, there are also some potential pitfalls. First, you may not use a cell phone that is currently supported by Salling Clicker. Second, if you turn your cell phone off, or leave the location without it, then your proximity is falsely detected and the system will not work well. Therefore, we will look at some other options for detecting where you are.
Keyfobs and HomeLink
In the previous articles we incorporated an RF connection into the automation system by using a W800RF32 wireless transceiver. This small device receives signals from various devices and sends them to your Mac via the USB connection.
Figure 1: Motion Detectors, Keyfobs, or PalmPads can be used to let your automation system know that you are around
One device is a small keychain fob, similar to ones used to remotely lock or unlock car doors that can be used to send signals to the wireless connection. They are available with four or eight buttons and can control on and off for two or four channels respectively. Therefore, you can set the buttons to signal when you arrive or leave the location.
Instead of always taking your keys with you, you can also use a PalmPad, which is a wireless control box with sets of buttons. This can be left by a door or in the main part of your house and used to signal your arrival or departure as well as control any other number of actions in your automated house.
Figure 2: HomeLink is a common, but rarely used feature in many cars.
Lastly, there is a little known, and little used feature probably lurking in your car known as 'HomeLink'. Normally a set of buttons may be located on the center console or the overhead console of your car. They are programmable RF buttons that are usually used for programming your garage door opener. They are also trainable to learn the RF signal for your automation system. To use a HomeLink button with your system, you need a keyfob or PalmPad. You need to get your HomeLink into 'training mode' (refer to your manual) and then press the button on your PalmPad to send out the training signal.
After doing this, you can now use the HomeLink button in your car to signal your coming and going.
Motion Detectors
All these devices and gadgets are great, but they still require you to either have the device with you, remember to turn it on, or push a button. The best automation systems do not require you to remember anything.
There are X10 wireless motion detectors available for a reasonably inexpensive price. These devices are battery operated and can be easily mounted indoors or outdoors to monitor your approach and travel as you enter, exit, and move through the building. The motion detector is configured to send out an RF signal to your W800RF32 when it detects motion. No additional wiring or equipment is required to receive the signals.
Here is an example scenario: you approach after dark, and the motion detector outside tells the system to turn on the outside floodlight and the light in the hallway. After you get inside and start moving through your house, lights in the room you are entering can turn on and the lights behind you will turn off.
You can even place a motion detector under your desk to detect when you have sat down at your computer to bring up your programs. All of this automation can occur without a push of a button.
What's my Computer up to?
Do you ever wonder what your computer is doing while you are away at work all day? Are the kids at home and doing their homework? Did you leave the heat on in the vacation home? You computer knows this and can share that information with you in a variety of ways.
In this section we will show you how your computer can alert you via email, a mobile SMS, instant message, or even call you. We will provide the same example use for each of these techniques: we want to be notified when someone comes into the house.
Send me an Email
First you will need to configure the Email settings in Indigo or XTension. This is done under the preferences and is similar to setting up any email client: SMTP server, username, password, port, and reply-to address. It may be useful to setup an account just for your house or office. This email account can then be useful for both sending out status messages and, as we will see, receiving commands.
Now that you have configured your email settings, your Mac will be able to send and receive email messages. We will set up our system to send us an email of the status of the automation system every day at 1PM. Using Indigo, you can add a Trigger Action, and set the condition to be based on either the state of a device, variable, or time. In the Action, you will call an AppleScript:
emailLog("you@example.com", "House status", 5)
on email(emailRecipient, emailSubject, emailBody)
tell application "IndigoServer"
send email to emailRecipient with subject emailSubject ¬
with body emailBody
end tell
end email
on emailLog(emailRecipient, emailSubject, n_lines)
tell application "IndigoServer"
set the_log to build event log list line count n_lines
my emailSend(emailRecipient, emailSubject, the_log)
end tell
end emailLog
As you noticed in the Condition tab, you can have more complex triggers than just time. For any of these notification systems they can be based on simple, or very complex criteria.
Your Mac can also receive messages in a POP inbox and trigger actions depending on keywords within the email or whom it is from. This last part is useful to reduce the risk of a spammer or prankster that gets a hold of the email address from playing havoc with your house or office.
Sending emails to your Mac is useful for activities such as turning on the heat to your house before you get home, or maybe telling your Mac to email you back with the current lights and temperature and who is home.
Send me an Instant Message
Sometimes you may want a more immediate notification that an event has occurred. Instant messaging usually pops up a window and can let us know when an event was detected. There are many options for sending out messages via iChat, AOL IM (using Adium), or even Skype. For example, we want to get an instant message when our daughter arrives home (we saw her cell phone, or a motion detector in her room that turned her light on for her).
sendiChatMessage("im_user", "Daughter arrived home")
on sendiChatMessage(receiver, message)
tell application "iChat"
send message to account receiver
end tell
end sendiChatMessage
Text Me
Email and Instant Messaging are both useful, but require you to be physically at your Mac. Some events should find you wherever you are at that moment. For this, you can have your automation system send you an SMS (Short Messaging System) to your mobile phone.
iChat supports sending SMS by using the full phone number, with +1 at the beginning. Therefore, we may want to get an SMS when a sensor in our basement detects rising water levels (perhaps your sump pump gave out again):
sendiChatMessage("+18005551212", "Basement flooding")
Call Me
In the most urgent of cases, or if you just don't want to deal with any messaging, you can use Skype to have your computer call you. At its simplest, Skype can call your phone number and hang up after a specified time period:
skypeCall("+18005551212", 10) -- call the office for 10 seconds
on skypeCall(phone_number, pause_time)
tell application "Skype"
activate
send command "CALL " & phone_number ¬
script name "Automation Script"
delay pause_time
send command "SET CALL 1 STATUS FINISHED " ¬
script name "Automation Script"
end tell
end skypeCall
It is possible to actually have your computer speak messages to you. For more information, check out SoundFlower (http://cycling74.com/downloads/soundflower) and the project notes at AppleFritter (http://applefritter.com/node/10758). Using AppleScript and SoundFlower, you can setup your own call-center or voice-messaging alert system that is setoff by triggers on your Mac or automation system.
Summary
We covered a lot of ways your computer can know where you are and let you know what is going on via email, SMS, instant messaging, and normal calling. Based on the techniques discussed in the first section, you can have your computer alert you only when you are not already home. It would be silly to get an SMS that your daughter is home when she is standing beside you in the kitchen! So get up out of your computer chair and start using your Mac from anywhere else in the world.
The full scripts, as well as additional scripts for setting your status and using other chat programs are available from the AutomationWiki: www.highearthorbit.com.