Constituate a wakeup event

MacOSX lets you schedule a single daily wakeup (/ shutdown, restart) event in the Energy Prefpane.
However, the latest version of MacUpdate allows for more such events, expectly by tweaking some low-level Unix settings via a shell script. Does anyone know of a way to program such event via Applescript (after which it is easy to program an action)…?

If you’re talking about “pmset”, you can use the “do shell script” command to execute shell scripts. Ie:

do shell script "pmset schedule poweron '10/10/06 12:00:00'"

That’s exactly it !
Is there also a way to list the entries made this way or to delete them…?

Sure, Eelco.

To list scheduled events:

do shell script "pmset -g sched"

To cancel a scheduled event:

do shell script "pmset schedule cancel poweron '10/10/06 12:00:00'"

(When setting, pmset must be run as root.)

Thanks Kai, this works very well…
…except when cancelling a weekday event such as


do shell script "pmset schedule cancel wakeorpoweron  repeat 'MTWRF 09:30:00'" password passW with administrator privileges

which gives problems with the (repeating) date

Hi Eelco.

To cancel repeating events:

do shell script "pmset repeat cancel" password passW with administrator privileges

If you had a secondary repeating event* that you wished to retain, then you’d probably have to reset it after cancelling.
(* Up to a pair of repeating events can be scheduled at any time; a power-on and a power-off event.)

Thanks.
This has helped me to create a script that guides you through the process.
I am aware that it does not handle all possible error conditions, and would be happy to have a pop-up menu for the actions but do not know how to create that.



set passW to "YourSysPassw"
set theRes to "None"
repeat
	set tEv to (do shell script "pmset -g sched" password passW with administrator privileges)'s paragraphs as list
	if "Repeating" is in (tEv's items as string) then ¬
		set tEv to {"----------» Remove all repeating events «----------"} & tEv
	set tR to (choose from list tEv with prompt "   List of power events:" OK button name "Add/Remove." with empty selection allowed) as string
	if tR = false or tR = "false" then return theRes
	if "Remove all repeating events" is in tR then
		do shell script "pmset repeat cancel" password passW with administrator privileges
	else
		set rr to "nobo"
		if tR ≠ "" then
			set tR to tR's text from word 1 to word (number of words of tR)
			set butt to {" Cancel ", "Add.", "Remove"}
			if number of items of tR < 1 then set butt to {" Cancel ", "Add."}
			if "]" is in tR then set tR to "[" & tR
			set rr to button returned of (display dialog tR buttons butt default button (count items of butt) with icon alias ((((path to system folder) as string) & "Library:CoreServices:Certificate Assistant.app:Contents:Resources:Certificate Assistant.icns") as string))
		end if
		if rr is " Cancel " then
			return theRes
		else if rr is "Remove" then
			try
				set DatePart to (word 4 of tR & "/" & word 5 of tR & "/" & word 6 of tR & " " & word 7 of tR & ":" & word 8 of tR & ":" & word 9 of tR)
				set aktion to word 2 of tR
				set theCmd to "pmset schedule cancel " & aktion & " '" & DatePart & "'"
				do shell script theCmd password passW with administrator privileges
			on error
				beep
				set rr to display dialog "Remove all repeating events instead...?" buttons {" Cancel ", "OK"} default button 2 with icon alias ((((path to system folder) as string) & "Library:CoreServices:Certificate Assistant.app:Contents:Resources:Certificate Assistant.icns") as string) --1
				if rr is " Cancel " then return theRes
				do shell script "pmset repeat cancel" password passW with administrator privileges
			end try
		else
			set rr to display dialog "Enter an event and date:" default answer "shutdown " & my getDateStr() & return & "" & "repeat wakeorpoweron MTWRFSU '09:30:00'" buttons {" Cancel ", "Add."} default button 2 with icon alias ((((path to system folder) as string) & "Library:CoreServices:Certificate Assistant.app:Contents:Resources:Certificate Assistant.icns") as string)
			set Answ to text returned of rr
			if button returned of rr is " Cancel " then return theRes
			if "Add" is in button returned of rr then
				repeat with h from 1 to count of paragraphs of Answ
					set hh to paragraph h of Answ
					if (count of words of hh) > 1 then
						set theCmd to "pmset  " & word 1 of hh & " " & text from word 2 to word -1 of hh & "'"
						if "repeat" is not in hh then set theCmd to "pmset schedule " & word 1 of hh & " '" & text from word 2 to word -1 of hh & ":00'"
						do shell script theCmd password passW with administrator privileges
					end if
				end repeat
			end if
		end if
	end if
	set theRes to do shell script "pmset -g sched" password passW with administrator privileges
end repeat
return theRes

on getDateStr()
	set cdate to current date
	set dd to (day of (cdate))
	set yy to text from character -2 to -1 of (year of (cdate) as string)
	repeat with MM from 1 to 12
		if month of (cdate) is equal to item MM of ¬
			{January, February, March, April, May, June, ¬
				July, August, September, October, November, December} then
			set cMM to text -2 thru -1 of ("0" & MM)
			set cDD to text -2 thru -1 of ("0" & dd)
			exit repeat
		end if
	end repeat
	set tt to text from character -8 to -4 of ((cdate) as string)
	set minz to word 2 of tt
	set minz to minz + 2
	if minz > 60 then
		set minz to minz - 60
		set yy to yy + 1
	end if
	if minz < 10 then set minz to "0" & minz
	set tt to text from word 1 to -3 of tt & minz
	return (cMM & "/" & cDD & "/" & yy & " " & tt) as string
end getDateStr