Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Temporarily suspend energy saver settings via script System
When watching videos in QuickTime Player and DVD Player, the screen saver and energy saver are automatically suspended, but not so if you're watching full-screen Flash video -- using the BBC iPlayer, for example. This AppleScript takes care of that problem:
(*
    Suspend Energy Saver © RickoKid 2008
    Version 0.1
  
    TODO: Change so that authentication only has to be given once for non-administrator users, no matter how long suspension is in place.

  
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*)

set userPass to ""
set battState to {powersource:"Battery", sleep:"", displaysleep:""}
set acState to {powersource:"AC Power", sleep:"", displaysleep:""}

if (do shell script "id -Gn") contains " admin" then
  (*  If user is admin, ask for password.  Otherwise, leave it to the system
    to ask username and password of an administrator (which will
    probably time out and ask again when ending suspension.  *)
  
  display dialog "Please type your password" default answer "" default button "OK" with hidden answer
  set userPass to text returned of the result
end if

set pmState to (do shell script "pmset -g disk") -->  Get current settings for both Battery and AC Power, and Screen Saver timeout. 
set saverState to (do shell script "defaults -currentHost read com.apple.screensaver idleTime") as number
repeat with stateSetting in paragraphs of pmState
  if stateSetting contains "Battery" then --> write following values to the battState record
    set powersource to (a reference to battState)
  else if stateSetting contains "AC Power" then --> write following values to the acState record
    set powersource to (a reference to acState)
  else if stateSetting contains " sleep" then
    set sleep of powersource to (word 2 of stateSetting)
  else if stateSetting contains " displaysleep" then
    set displaysleep of powersource to (word 2 of stateSetting)
  end if
end repeat

-->  Disable sleep, displaysleep and screen saver for both Battery and AC Power
if userPass is not "" then (do shell script "pwd" password userPass with administrator privileges) --> If we have a admin password, activate it.
set battSleepResult to (do shell script "pmset -b sleep 0" with administrator privileges and password)
set battdisplayResult to (do shell script "pmset -b displaysleep 0" with administrator privileges and password)
set acSleepResult to (do shell script "pmset -c sleep 0" with administrator privileges and password)
set acdisplayResult to (do shell script "pmset -c displaysleep 0" with administrator privileges and password)
set ssResult to (do shell script "defaults -currentHost write com.apple.screensaver idleTime 0")

display dialog 
  "Sleep and Screensaver are now temporarily suspended." with title 
  "Energy Saver Suspended" buttons {"Resume"} default button "Resume" with icon 1

-->  Re-enable sleep, displaysleep and screen saver for both Battery and AC Power, by restoring the saved settings.
if userPass is not "" then (do shell script "pwd" password userPass with administrator privileges) --> If we have a admin password, activate it.
set battSleepResult to (do shell script "pmset -b sleep " & sleep of battState with administrator privileges and password)
set battdisplayResult to (do shell script "pmset -b displaysleep " & displaysleep of battState with administrator privileges and password)
set acSleepResult to (do shell script "pmset -c sleep " & sleep of acState with administrator privileges and password)
set acdisplayResult to (do shell script "pmset -c displaysleep " & displaysleep of acState with administrator privileges and password)
set ssResult to (do shell script "defaults -currentHost write com.apple.screensaver idleTime " & saverState)
The above script will temporarily suspend the Energy Saver and screen saver until you click the Resume button. If you're logged in as an administrator, you'll need to provide your password first. (The original version of this script can be found in this post on my site.)

[robg adds: I haven't tested this one...]
    •    
  • Currently 1.25 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (4 votes cast)
 
[12,854 views]  

Temporarily suspend energy saver settings via script | 8 comments | Create New Account
Click here to return to the 'Temporarily suspend energy saver settings via script' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Temporarily suspend energy saver settings via script
Authored by: schifrin on May 23, '08 08:39:42AM

As astounding as it may seem, the program I use to color calibrate my monitors for photo color correction (Spyder) does not disable the Energy Saver. The process, thus, requires me to jiggle the mouse every minute or two while the calibrations take place. Thanks very much for letting me correct their oversight.
-SS-



[ Reply to This | # ]
or simply use CAFFEINE ;)
Authored by: dahui on May 23, '08 09:39:01AM
or simply use CAFFEINE ;)
Authored by: osxpounder on May 30, '08 02:47:49PM

I recommend Caffeine, too. I haven't used it on Leopard, yet, but it has served very well on Tiger.



[ Reply to This | # ]
Temporarily suspend energy saver settings via script
Authored by: richwiss on May 23, '08 09:02:08PM

I agree with the above -- I use Caffeine, too. It's simply and easy to use, and works well.



[ Reply to This | # ]
Temporarily suspend energy saver settings via script
Authored by: sojourner on May 25, '08 02:52:53AM

another vote on caffeine. great little program.



[ Reply to This | # ]
Temporarily suspend energy saver settings via script
Authored by: zpjet on May 26, '08 02:22:11PM

um. i just needed this today while watching something on iPlayer and thought i will just use Active Screen Corners but they apparently work only with the screen saver not energy saver... pity.



[ Reply to This | # ]
Temporarily suspend energy saver settings via script
Authored by: blarged on May 29, '08 05:55:39PM
This script did not work for me on 10.5.2 I downloaded the original script at the site linked from the hint. Apparently the shell script line
do shell script "defaults -currentHost read com.apple.screensaver idleTime"
does not work

[ Reply to This | # ]
Temporarily suspend energy saver settings via script
Authored by: DeminJanu on Jun 20, '09 12:56:44AM
maybe it's supposed to be:
do shell script("defaults -currentHost read com.apple.screensaver idleTime")

I was just setting my screensaver time like this, and I had to use:
do shell script ("defaults -currentHost write com.apple.screensaver idleTime 900")

just a guess

[ Reply to This | # ]