I have several pieces of server software installed on my MacBook Pro for work using Homebrew. There is one service in particular, that likes to peg the CPU after the OS wakes up from sleep until I restart it. The service is currently managed by launchd, and I am wondering if there is a way for me to tell launchd to stop the service when the OS goes to sleep, and then start it up again on wake.

  • Aim to only schedule work at wake-up. The misbehaving process can be reset by the solution you choose; rather than by stopping on sleep and starting on wake. The time between a sleep notification being issued and the sleep occurring is limited and can not be relied upon to perform interprocess work. – Graham Miln Feb 8 '14 at 16:33

You can use SleepWatcher:

It can be used to execute a Unix command when the Mac or the display of the Mac goes to sleep mode or wakes up, after a given time without user interaction or when the user resumes activity after a break or when the power supply of a Mac notebook is attached or detached.

Run launchctl load <path> and launchctl unload <path> with SleepWatcher on wake and sleep respectively.


I ended up using ControlPlane's Laptop Lid Open/Closed event to switch to a context that stops and starts the service using laucnchctl.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .