Re: Wake from Sleep
Re: Wake from Sleep
- Subject: Re: Wake from Sleep
- From: Jeffrey Berman <email@hidden>
- Date: Sun, 01 Aug 2004 12:01:42 -0500
On 7/31/04 8:56 PM, email@hidden <email@hidden> wrote:
>
Embed the following, quick and dirty, code segment into your existing
>
AppleScript code.
>
>
----- code starts here -----
>
>
tell application "System Preferences"
>
activate -- Set 'System Preferences' as the frontmost process.
>
>
-- Display the 'Energy Saver' Utility of 'System Preferences'.
>
set current pane to pane "com.apple.preference.energysaver"
>
end tell
>
>
tell application "System Events"
>
tell process "System Preferences"
>
tell tab group 1 of group 1 of window "Energy Saver"
>
>
-- Select the 'Sleep' panel.
>
click radio button "Sleep"
>
>
If the 'Put the display to sleep when the computer is inactive for:'
>
check box is set, continue ...
>
if ((value of checkbox 1) = 1) then
>
>
-- Obtain the value of the second slider.
>
set theValue to (value of slider 2) as number
>
>
-- Toggle the 'Put the display ...' check box, to remove the check mark.
>
-- This should cause the Mac to hiccup and the display to turn ON.
>
click checkbox 1
>
>
-- Wait a second or two.
>
delay 2
>
>
-- Toggle the 'Put the display ...' check box, to add a check mark.
>
click checkbox 1
>
>
-- Restore the second slider to its previous value.
>
set (value of slider 2) to theValue
>
end if
>
>
end tell
>
end tell
>
end tell
>
>
tell application "System Preferences" to quit
>
>
---- code ends here -----
>
>
To test the above - I set the Energy Saver 'Put the display ...'
>
slider to '1 minute', added 'delay 70' just above the code provided
>
above, ran the code, and did not touch the mouse.
>
>
After one minute the display went turn OFF - actually the display's
>
video feed from the Mac was turned OFF. Ten seconds later the
>
display turned ON [the video was restored]. Also, the 'Put check box
>
was restored as well as its associated slider's value.
>
>
Feel free to taper with the code as you see fit.
Thanks for responding to my question of how to use AppleScript to get a
machine to wake from sleep. Unfortunately, my code needs to function on
computers running OS X 10.2, where GUI scripting is not available. However,
your comments did suggest a Unix solution using the 'do shell script'
command.
>
The file
>
'/Library/Preferences/SystemConfiguration/com.apple.PowerManagement.plist' is
>
what is updated when one modifies the 'System Preferences' 'Sleep' utility's
>
settings. Since 'AC Power' of the 'com.apple.PowerManagement.plist' file is a
>
'Dictionary' I do not know how you can access the dictionary's 'Display Sleep
>
Timer's value via 'Terminal's 'default' command or an AppleScript 'do shell
>
script' command.
The Unix 'pmset' command gives the settings and allows you to change them.
Therefore, one could accomplish the same resetting you proposed with the
following syntax:
set DimValue to do shell script "pmset -g disk | awk '/dim/ {print $2}'"
-- get current value for display sleep
get "sudo pmset -c dim 0"
do shell script result password PW with administrator privileges
-- set display sleep to never to activate display
get "sudo pmset -c dim " & DimValue
do shell script result password PW with administrator privileges
-- restore display sleep setting
(where PW is a variable containing the administrator's password.) This
approach would work with machines running OS X 10.2.
>
If this code is of any assistance to you - please, remember to post your
>
findings, with the code you use, on the AppleScript Users List
>
<email@hidden> for the benefit of others, as well.
Done.
The remaining issue is how to have the code run only when the display is in
a sleep state. Does anyone know of a way to get the sleep status of the
display?
-Jeffrey Berman
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.