Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using my iPad to remotely develop apps (I test when I get back to my iMac) and to make other small changes to files on my computer. Until now, I've been using TeamViewer for iOS and iMac and it has worked, until the time I tried to access my iMac from a Windows 7 machine. Then, one time, TeamViewer crashed.

I am looking for a way to reboot my Mac when the remote program fails. Is there an Applescript that con do this?

Also, is there a VNC program that has a compatible iOS app that does support remote reboot?

share|improve this question
up vote 0 down vote accepted

You don't need to reboot to re-start TeamViewer; you can get launchd to monitor the process and re-start it if it crashes.

First, you'll need to identify the actual executable. Open a terminal and look around in the TeamViewer bundle - the executable will likely be at /Applications/ but your mileage may vary. To check you've found the right path, type it in the terminal - if TeamViewer starts, you've probably got it. Alternatively, open Activity Monitor while TeamViewer is running, identify the TeamViewer process and click 'Inspect' in the toolbar. Then, in the Open Files and Ports tab, the executable will likely be the first or second entry listed (after /).

Once you know what program you're tracking, you can create a launchd Property List. This is an XML file, so you can do it with your favourite text editor or alternatively you can use the Property List Editor that's installed with the Mac OS X Dev Tools. Create the following:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "">
<plist version="1.0">



Save this in ~/Library/LaunchAgents/, then open a terminal and do:

launchctl load ~/Library/LaunchAgents/

This will cause launchd to load the item which will cause it to monitor the specified program and, if it exits for any reason, it will be re-started. This will only run if your user is logged in. To run at boot, put the plist in /Library/LaunchDaemons/, add UserName and GroupName key/value pairs and use sudo when running launchd load. To get rid of the item (if you genuinely need to quit TeamViewer, for instance) simply replace load in the above command with unload.

Alternatively, Lingon provides a graphical interface to launchd, and may be easier.

share|improve this answer

You could set up a task on the iMac to check for the existence of the TeamViewer process, and reboot if it's not found. But why not just restart the process rather than rebooting the whole machine?

share|improve this answer
That is an interesting idea. How would I do that? – Moshe Oct 8 '10 at 0:14
ps -au nick | grep [0-9]./Applications/ – Nick Oct 8 '10 at 5:21
Sorry, I was going to edit the previous post - here is a more complete version: ps -au nick | grep [0-9]./Applications/ || open /Applications/ -- just figure out what process needs to remain started and replace the "" and "nick" with your own OS X user name. Now add it as a cron job and set it to run every minute. – Nick Oct 8 '10 at 5:28
Even better, use launchd, which is specifically designed for this.… gives an example that keeps TextEdit alive. – Scott Oct 8 '10 at 16:52
@Scott - please post as an answer. This may be it. – Moshe Oct 19 '10 at 23:31

This is fairly trivial if you're familiar with the command line. Many SSH clients exist for iOS: you'd need to activate "Remote Login" from the sharing preference pane.

Once this is done and the proper networking minutia are taken care of, all you'd need to do to reboot is SSH into your iMac and run $ sudo shutdown -r now, which will reboot the machine. Assuming that's all you need to do to get TeamViewer up and running, that should work fine.

Someone else suggested restarting the process. Again, assuming all you need to do to activate TeamViewer is to launch the application, you would first need to force-quit the existing hung process: something like $ sudo killall TeamViewer, and then relaunch the application with $ open /Applications/ or something similar.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.