Wake from sleep

Hi,
i want to instruct my mac to wake from monitor sleep. I found nothing suitable googling around.
Mine does not work. Here a try:

tell application "System Events"
	#stop rand_screensaver
	if exists process "ScreenSaverEngine" then
		tell application "ScreenSaverEngine" to quit
		beep
		tell application "Finder" to activate
	end if
end tell

Hello.

Maybe SleepWatcher does what you want, or maybe SleepX (deprecated in Mavericks.)

I’ve experimented in the past with the “System Events” power and processes suite, but I never found a way to wake up a sleeping system, I discovered that sofware has no control over the system when sleeping, only the hardware seems capable of waking it up via a mouse or keyboard click.

You can use “System Events” to log out, restart, shut down, or even send it to sleep, but wake up seems to ba a know go.

I noticed your script trying to access the screen saver process, so I’ve given some examples below to show an easier way to operate the screen saver, just in case you where interested in that side of things.


-- Start and Stop the screen saver
tell application "System Events"
	start current screen saver
	delay (10)
	stop current screen saver
end tell

OR


my startScreenSaver("Flurry") -- Make sure the "Flurry screen saver is installed
delay (10)
my stopScreenSaver()

on startScreenSaver(screenSaverName)
	tell application "System Events"
		start screen saver screenSaverName
	end tell
end startScreenSaver

on stopScreenSaver()
	tell application "System Events"
		stop current screen saver
	end tell
end stopScreenSaver

Regards Mark

Hello.

Maybe simulating some keystrokes from a script run by SleepWatcher can revive it. :slight_smile:

tell application id "com.apple.systemevents"
	tell application process "Finder"
		keystroke tab using command down
		key code 53
	end tell
end tell

Edit

Simulated keystrokes doesn’t work for waking up a screen, the caffeinate utility further down the thread works however.

i found this:

	set thetime to thehour & ":" & theminutes & ":" & theseconds
	--clean wakup-plan
	do shell script "pmset repeat cancel" with administrator privileges
	--set the plan
	do shell script "pmset repeat wakeorpoweron MTWRFSU \"" & thetime & "\"" with administrator privileges

but this works only with admin privileges. Moreover, this might work only for computer sleep and NOT for display sleep.

edit:
Waking display from terminal, general waking

Mark, i’ll return and post some results, if you’re interested.

SleepWatcher can be found here

You could use this to install something, that will wake your display up after a given time interval.

Hello

This should wake your monitor up. You can use that with the SleepWatcher above. Caffeinate has a manual page: man -s8 caffeinate There should be a caffeinate utility somwhere if you haven’t got one delivered with your system.

delay 4
do shell script "caffeinate -u true"

McUsrII,
thats kind!

i’ll try Sleepwatcher, this is sure. Meanwhile i did some experiments:

(*
tell application "System Events"
	set d to screen saver "Flurry"
	start d
end tell
*)
set old_time to current date
#do shell script "sleep 780" #13min #debug"sleep 10" #
#stop rand_screensaver
#wake in 13 minutes
set set_time to my get_time(old_time)
#return set_time
set wake_up to ("pmset schedule wake = \"" & set_time & "\"" as text) #& "destroyfvkeyonstandby 0" as text)
#set wake_up to "pmset -g assertions"
do shell script wake_up # "01/01/2012 20:00:00"
#do shell script "pmset schedule wake = \"27.12.13 23:08:00 MEZ\""

on get_time(old_time)
	set {ddy, mmth, yyr} to {day, month, year} of old_time
	set mmth to mmth as number
	set yyr to text -2 thru -1 of (yyr as text)
	if length of (ddy as text) = 1 then set ddy to "0" & ddy
	if length of (mmth as text) = 1 then set mmth to "0" & mmth
	
	set wake_hour to old_time + 10 # debug, 10 secs(1 * 60)
	set {whour, wmin} to {hours, minutes} of wake_hour
	if length of (whour as text) = 1 then set ddy to "0" & whour
	if length of (wmin as text) = 1 then set wmin to "0" & wmin
	set wake_tt to whour & ":" & wmin & ":" & "00 MEZ"
	
	return ddy & "." & mmth & "." & yyr & space & wake_tt
end get_time

i get always “Error: badly formatted date (2)”. Don’t know how to write a better time, i tried some combinations, using points, slashes, quotes, middle-european time, the -g assertions time example, and so forth.

set wake_up to "pmset -g assertions"
do shell script wake_up
(*
"27.12.13 22:57:07 MEZ    
Assertion status system-wide:
   PreventUserIdleDisplaySleep             0
.
*)

the shipped man help of pmset was written in 2006, it may be broken in Lion and higher, i think. Thats a shame.:rolleyes:

Hello I think your date format should be good when you get rid of the Timezone.

Here is an excerpt from the (newer) pmset manual:

Tadaa!
i worked out a nice script.
Get it here:
Healthcare

Thanks to McUsrII for the nice suggestions.