Scheduling a “sleep” event on Power Manager

batterysleep-wake

I am using Mac OS El Capitan on my macbook pro and have just installed Power Manager following your recommendations elsewhere on this website (see Low Battery Alert for Mac OS X El Capitan).

However, I see only an option to power down the computer when the battery charge falls below a specified level. I would like to simply display a pop-up warning on the screen along with a sound alarm and, if continued unheeded for a few minutes, put the laptop to sleep instead of powering down. I guess the way to achieve this would be a script; could you send me such a script indicating wherever I have to insert my preferred parameters? Thanks.

Best Answer

Below are the steps to creating an event to run an AppleScript when the battery level drops below 30%:

  1. Power Manager > File (menu) > New Empty Event;
  2. Double-click new Untitled event to open in editor;
  3. Add a trigger > Power Remaining > Battery 30% Left
  4. Add an action > Run Script > AppleScript
  5. AppleScript action > Cog > Edit
  6. Copy and paste in the AppleScript below
  7. Apply then Save

AppleScript to copy and paste into event:

#!/usr/bin/osascript
try
    with timeout of 10 seconds
        display dialog "Your battery has dropped below 30%" with icon caution buttons {"OK"} default button 1
        say "Low battery" 
    end timeout
on error -- likely timeout
    tell application "Finder" to sleep
end try

I wrote Power Manager. If you need support for Power Manager, please get in touch via support@dssw.co.uk.

Power Manager low power warning