-- adapted from leenoble's script at http://www.macosxhints.com/article.php?story=20050126064329159 property idleTest : 15 * 60 -- How long to be idle (in seconds) before sleep kicks in property sleepState : false property delayTime : 60 -- how often to check initially on idle_time() set idleTime to (do shell script "ioreg -c IOHIDSystem | perl -ane 'if (/Idle/) {$idle=(pop @F)/1000000000; print $idle,"";last}'") -- disable when not testing --say idleTime as integer return idleTime end idle_time script should_quit set idleComp to false -- this repeat loop polls the idle time every n seconds to determine -- whether the system has been idle for the number of seconds defined in idleTest -- It will repeat indefinitely repeat --while idleComp is false set idleTime to idle_time() of parent set old_delims to AppleScript's text item delimiters set AppleScript's text item delimiters to "." set idleTime to ((first text item of idleTime as string) as integer) set AppleScript's text item delimiters to old_delims set idleTest to (idleTest as integer) if idleTime is less than idleTest and sleepState = true then -- optional alert line say "waking up" -- nap mode off do shell script "hwprefs cpu_nap=false" -- use single procs do shell script "hwprefs cpu_count=2" set sleepState to false -- while active checks every minute set delayTime to 60 else if idleTime is greater than idleTest and sleepState = false then set idleComp to true try -- optional alert line say "sleeping" ignoring application responses -- nap mode on do shell script "hwprefs cpu_nap=true" -- use single proc do shell script "hwprefs cpu_count=1" set sleepState to true end ignoring end try -- while inactive checks checks for wake every 10 seconds set delayTime to 10 end if delay delayTime end repeat end script tell should_quit to run