How to detect that the Mac just woke up

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).
lee.sailer wrote on :

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

Greg Shenaut replied on :

lee.sailer@redacted.invalid lee.sailer@redacted.invalid 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

Bev A. Kupf replied on :

On 5 Feb 2005 07:07:43 -0800, lee.sailer@redacted.invalid (lee.sailer@redacted.invalid) 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

Michael Vilain replied on :

In article slrnd09qr4.8vd.bevakupf@redacted.invalid, "Bev A. Kupf" bevakupf@redacted.invalid wrote:

On 5 Feb 2005 07:07:43 -0800, lee.sailer@redacted.invalid (lee.sailer@redacted.invalid) 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.