MacDevCenter    
 Published on MacDevCenter (http://www.macdevcenter.com/)
 See this if you're having trouble printing code examples


Homemade Dot-Mac: Remote Control

by Alan Graham
12/07/2004

If you've followed along with other Homemade Dot-Mac (from here on--HDM) articles, you are probably well aware of the value in running your own home server and the possibilities it opens in your life. From hosting your own website to running a file server, the options are almost endless. But what about controlling your Mac from a remote location? Sure, a remote ssh connection and a command line can do a lot, but can it let you actually see your screen? And maybe you just aren't that technical. In this article I'll show you a free way to control your home computer from any location in the world, and I promise it is easy and painless. We're simply using VNC and you'll be up and running in minutes.

What is VNC?

VNC stands for Virtual Network Computing. It was developed by AT&T Laboratories Cambridge. Very simply, the whole mechanism consists of a VNC server-application on the machine you wish to control, and a VNC viewer-application on the machine doing the controlling. Simple and elegant.

The beauty of VNC is that it is a relatively small application in size, it is platform independent, sharable (many computers can view and be accessed by several machines at a single time), and it is free under the terms of the GNU Public License.

Value?

So why would you want to control a Mac from a remote location? How many times have you received a call from a loved one or friend who is having trouble with their machine? Talking through a problem when you can't see their screen is maddening. With VNC, you can login remotely, see their screen, take control of their mouse, and fix the problem.

Or perhaps you run something like a home automation program, a web server, or maybe use your Mac as an answering machine. If you are on the road and for some reason it isn't working, what will you do then? Using VNC to login, you can resolve these issues quickly and painlessly.

Homemade Dot-Mac

The first step in setting up a remote VNC server (if you don't have a static IP) is to first set up an HDM server. After you've accomplished this, you need to download a VNC server-application and a VNC viewer-application. While there are a great many choices for this, for the sake of this tutorial we'll focus on two of my favorites, Share My Desktop and Chicken of the VNC.

The Server

Share My Desktop, created by Mike Bombich, "is a simple little wrapper application that I created for OSXvnc in AppleScript Studio. SMD makes initiating a VNC server very simple -- just click a button!"

I couldn't have said it better myself.

Let's start by downloading the application Share My Desktop to the machine you wish to control, your HDM server. The .dmg file should mount itself in your Finder window. From there, simply drag the application to your Applications folder and launch it.

For the sake of preserving my IP address I'm using an internal IP for this demonstration. This does however apply if you wish to control machines from within your home or network. So, you might find a similar IP address if your machine is running behind a firewall or router. In the HDM articles prior to this, you can learn ways to ensure that you can connect to your machine from outside the home, even if it is masked, using port forwarding, or DMZ.

First thing we want to address is Share My Desktop>Preferences. Under this heading we'll find the following screen:

Here you can select which port you wish to use, password settings, and Energy Settings. We don't really want to allow a HDM machine to go to sleep in any situation or we won't be able to connect with it. However, allowing the screen to dim is alright.

Now we are already to run our VNC server-application by just clicking "Start sharing," but this server as it is currently configured will only run if the application Share My Desktop is running. What if it crashed? What if you are away and your power fails? You might want to actually install the server so that it always runs at startup. In this scenario, you never actually run the application again.

The first thing you want to do is visit the Energy Saver Preferences and in Options select "Restart automatically after a power failure." Even with a backup UPS system, your Mac can't run indefinitely without power. This setting will ensure that your Mac always comes back to life when the juice returns.

Then, under the "Sleep" tab, make sure your machine never goes to sleep.

The next step is to configure or manage the VNC server. You'll find this in the Share My Desktop application under File>Manage System VNC Server. First click the Lock in the bottom, left-hand corner and enter your Admin password so that you can make changes.

Then check off “Start VNC server on startup,” and click "Install System VNC." If you make any other changes be sure to click on "Apply Settings."

Now simply click "Turn on System VNC."

We're ready to rock!

Keep in mind that if you install the VNC server, there is no need to run the Share My Desktop application. Simply make sure you note the server's port number, ensure it has the appropriate password, apply those settings, and turn it on. Then just quit the program.

Chicken of the VNC

Now, while Jessica Simpson might actually believe this is chicken, the rest of us realize this is a VNC viewer-application. First thing to do is download the application to the machine that will serve as the remote control.

Drag the application to the Applications folder and launch it. Here we see a screen with the option to create a list of server connections to login to. If you have an HDM at home, you would enter that domain name in the "Host" field or the local IP address on your network. In my example, I'm simply using my network's localized IP. Enter the Port and the Password. Click Shared Display if you are sharing the connection with multiple clients. Then click connect and prepare to be amazed!


Create a server connection: Enter a Host, Port, Password, and click Connect.


Here we see two machines. The one in front is the server (Share My Desktop), the one in back is the client (Chicken of the VNC). Note that the PowerBook display in the front appears as a window on the PowerBook display behind it. And you can see iTunes running on the machine in the back, behind the VNC application.

How easy was that?

So now you can fix a problem remotely, change a setting, actually control and use applications, or spy on those sneaky teenagers. You name it.

Note: A good VNC client for controlling a Mac from Windows, one that I prefer, is RealVNC.

Alan Graham is the creator of the Best of Blogs book series and is a frequent writer on the O'Reilly Network.


Return to MacDevCenter.com.

Copyright © 2009 O'Reilly Media, Inc.