The conversation on this page has been archived and is no longer active.

How to detect that the Mac just woke up

Message #1 - Posted 2005/02/05 - lee.sailer@direcway.com

OS X 10.3.x

The Mac is set to go to sleep once in awhile. When it wakes up, I want it to stop and restart a background process (ntpd). I can write the script. That parts easy. How can I *detect* that it just woke up?

ideas welcome.

lee

Message #2 - Posted 2005/02/05 - Greg Shenaut

lee.sailer@direcway.com <lee.sailer@direcway.com> exponit:

OS X 10.3.x

The Mac is set to go to sleep once in awhile. When it wakes up, I want it to stop and restart a background process (ntpd). I can write the script. That parts easy. How can I *detect* that it just woke up?

ideas welcome.

I don't know the correct answer, but I do know how your script could do it. Assume that the script is in a sleep loop, and that it sleeps when the system sleeps. So, each time around your loop, set a variable to the current system time (date +%s) and compare it to the value of the previous loop's time; if it is greater than the your programmed sleep interval, then the system has just awakened. Otherwise, save the current time in the "previous time" variable and loop.

Why do you want to restart ntpd after awakening from a sleep?

Greg Shenaut

Message #3 - Posted 2005/02/05 - Bev A. Kupf

On 5 Feb 2005 07:07:43 -0800,
lee.sailer@direcway.com wrote:

OS X 10.3.x

The Mac is set to go to sleep once in awhile. When it wakes up, I want it to stop and restart a background process (ntpd). I can write the script. That parts easy. How can I *detect* that it just woke up?

A Google search indicates that you can use Sleepwatcher to detect wake up from sleep. The Versiontracker description begins with, "SleepWatcher is a command line tool (daemon) for Mac OS X that executes a command or shell script when the Mac goes to sleep mode or wakes up from sleep".

But, as has been asked in a previous post, why do you need to restart ntpd?

Beverly

Many a smale maketh a grate -- Geoffrey Chaucer

Message #4 - Posted 2005/02/05 - Michael Vilain

Previously, Bev A. Kupf wrote:

On 5 Feb 2005 07:07:43 -0800, lee.sailer@direcway.com wrote:

OS X 10.3.x

The Mac is set to go to sleep once in awhile. When it wakes up, I want it to stop and restart a background process (ntpd). I can write the script. That parts easy. How can I *detect* that it just woke up?

A Google search indicates that you can use Sleepwatcher to detect wake up from sleep. The Versiontracker description begins with, "SleepWatcher is a command line tool (daemon) for Mac OS X that executes a command or shell script when the Mac goes to sleep mode or wakes up from sleep".

But, as has been asked in a previous post, why do you need to restart ntpd?

Beverly

AFAIK, you don't need to restart ntpd. It's still running on your system. It will sort things out when you wake. If you clock isn't behaving, chances are you need a new battery.

DeeDee, don't press that button! DeeDee! NO! Dee...

Need Help? Have a Question?

Looking for more help, comments, and answers?

Ask your questions on Ask Different. Ask Different is a community of Apple users ready to help.