I use this (BetterDialog AS extension required!)
set passW to text returned of (display dialog "Enter password:" default answer "xxx")
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
with timeout of 150 seconds
tell application "System Events" to set fappl to name of some application process whose frontmost is true
set fApp to short name of (info for (path to frontmost application))
set givingUpTime to 45
do shell script "osascript -e 'do shell script \"sleep " & givingUpTime & "\" ' -e 'tell application \"System Events\" to tell application process \"" & fApp & "\" to keystroke \".\" using {command down}' > /dev/null 2>&1 & "
tell application fappl to activate
tell application fappl to set tR to (choose from list tEv with prompt " List of power events:" OK button name "Add/Remove." with empty selection allowed) as string
(*try
tell application fAppl to activate
tell application fAppl to (list dialog)
on error
tell application "QuicKeys" to play shortcut named "Cmd."
set tR to false
end try*)
end timeout
if tR = false or tR = "false" then return theRes
if "Scheduled power events" is in tR or "Repeating power events:" is in tR then
else 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
tell application fappl to activate
tell application fappl to 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
tell application fappl to 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
--try
set {EventChoice, OccurrenceChoice, EventDate, PasswChoice, PassRemChoice} to my getBetterChoose(fApp, passW)
if "File launch" is in EventChoice then
if character 1 of EventDate = "M" then set EventDate to text from word 2 to -1 of EventDate
my defineTimedFav(text 1 thru 2 of EventDate & "." & text -2 thru -1 of EventDate)
return
end if
if "Wakeup" is in EventChoice then set EventChoice to "wakeorpoweron"
set theCmd to "pmset schedule " & EventChoice & " '" & EventDate & "'"
if "repeat" is in OccurrenceChoice then set theCmd to "pmset repeat " & EventChoice & " " & EventDate & "'"
-- display dialog (EventChoice & return & OccurrenceChoice & return & EventDate & return & theCmd) as string
do shell script theCmd password passW with administrator privileges
end if
end if
set theRes to do shell script "pmset -g sched" password passW with administrator privileges
end repeat
return theRes
on defineTimedFav(tim)
tell application "Finder"
set scriptFile to ((name of startup disk) & ":Library:Scripts:Launching scripts:Make Timed Favorite.scpt") as string
try
set menuScript to load script file scriptFile
on error
set scriptFile to (reveal file scriptFile) as string
close window 1
set menuScript to load script file scriptFile
end try
end tell
tell menuScript to go("", false, tim)
end defineTimedFav
on getDateStr()
tell (current date)
tell time to tell ((10000 + it div hours * 100 + it mod hours div minutes + 2) as string) to set t to text 2 thru 3 & ":" & text 4 thru 5
tell (year * 10000 + (its month) + day * 100) as string to set d to text 7 thru 8 & "/" & text 5 thru 6 & "/" & text 3 thru 4
end tell
return d & " " & t
end getDateStr
on getBetterChoose(fappl, passW)
set myChoices2 to {"Start & WakeUp", "Sleep", "ShutDown", "File Launch"}
set myChoices3 to {"Single", "Repeating"}
set salut to "New System Event:"
repeat
tell application fappl to set myResult to display better dialog ¬
¬
salut fields {{kind:popup menu, name:"Event type: ", field menu items:myChoices2}, ¬
{kind:popup menu, name:"Occurrence:", field menu items:myChoices3}} ¬
buttons {"OK", "Cancel"}
set myname to "Eelco"
set myPassword to "EelcoPW"
-- Typical way of getting data out of this kind of dialog:
set EventChoice to field value of item 1 of fields returned of myResult
set OccurrenceChoice to field value of item 2 of fields returned of myResult
set DateStuff to {{kind:text field kind, name:"Date:", field value:"mm/dd/yy"}}
set theErr to ""
if EventChoice = "File Launch" and OccurrenceChoice ≠"Repeating" then
set OccurrenceChoice to "Repeating"
set salut to salut & return & "(file launch is repeating all weekdays !)"
beep
end if
set hrz to {"00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "23"}
set minz to hrz
repeat with i from 24 to 60
set minz to minz & {i}
end repeat
repeat
tell (current date) to tell time to tell ((10000 + it div hours * 100 + it mod hours div minutes) as string)
set currHour to text 2 thru 3
set currMin to ((text 4 thru 5) as number)
end tell
set currMin to currMin + 2
if OccurrenceChoice is "Repeating" then
set DateStuff to {{kind:text field kind, name:"Weekdays", field value:"MTWRFSU"}}
set timeStuff to {{kind:popup menu, name:"Hour:", field menu items:hrz, field value:currHour}, ¬
{kind:popup menu, name:"Minute:", field menu items:minz, field value:currMin}} -- {{kind:text field kind, name:"Time:", field value:"hh:mm"}}
else
set mo to (month of (current date) as number)
set todayy to (day of (current date) as number)
set Yr to " " & year of (current date)
set {daytes, montz, dayz, yrz} to {{}, {}, {}, {year of (current date)}}
repeat with i from 1 to 9
set yrz to yrz & {(yrz's last item) + 1}
end repeat
repeat 12 times
set n to (do shell script "cal " & mo & Yr)
set montz to montz & {{word 1 of n}}
set daytes to daytes & paragraphs 2 thru -1 of n
set mo to (mo + 1) mod 12
if mo = 0 then set mo to 12
if mo = 1 then set Yr to " " & ((year of (current date)) + 1)
end repeat
repeat with k from 2 to number of items of daytes
set gg to words of daytes's item k
set dayz to dayz & gg
if k > 5 then exit repeat
end repeat
set DateStuff to {{kind:popup menu, name:"Year:", field menu items:yrz}, ¬
{kind:popup menu, name:"Month:", field menu items:montz}, ¬
{kind:popup menu, name:"Day:", field menu items:dayz, field value:todayy}, ¬
{kind:popup menu, name:"Hour:", field menu items:hrz, field value:currHour}, ¬
{kind:popup menu, name:"Minute:", field menu items:minz, field value:currMin}}
set timeStuff to {}
end if
tell application fappl to set myResult to display better dialog ¬
theErr & return & salut fields ¬
{{kind:popup menu, name:"Event type:", field menu items:EventChoice}, ¬
{kind:popup menu, name:"Occurrence:", field menu items:OccurrenceChoice}} & ¬
DateStuff & timeStuff & ¬
{{kind:password field, name:"Your password:", field value:passW}, ¬
{kind:check box, name:"Remember password", field value:checked state}} ¬
buttons {"OK", "Cancel"}
set blijfVragen to false
if OccurrenceChoice = "Repeating" then
set DateChoice to ""
set DateChoice to field value of item 3 of fields returned of myResult
set TimeChoice to "'" & field value of item 4 of fields returned of myResult & ":" & field value of item 5 of fields returned of myResult & ":00" -- was met keyB entry: field value of item 4 of fields returned of myResult
if EventChoice = "File Launch" then set TimeChoice to field value of item 4 of fields returned of myResult
set PasswChoice to field value of item 6 of fields returned of myResult
set PassRemChoice to field value of item 7 of fields returned of myResult
else
set YearChoice to field value of item 3 of fields returned of myResult
set monthChoice to field value of item 4 of fields returned of myResult
set DayChoice to field value of item 5 of fields returned of myResult
set TimeChoice to field value of item 6 of fields returned of myResult & ":" & field value of item 7 of fields returned of myResult & ":00:00"
set PasswChoice to field value of item 8 of fields returned of myResult
set PassRemChoice to field value of item 9 of fields returned of myResult
set DateChoice to my getMonthNum(monthChoice) & "/" & DayChoice & "/" & YearChoice
set checkDateChoice to DayChoice & "/" & my getMonthNum(monthChoice) & "/" & YearChoice & " " & TimeChoice
try
set checkDate to (date (checkDateChoice)) - (current date)
if checkDate < 1 then --tell application fAppl to display dialog checkDate as string
beep 2
tell application fappl to set myResult to display dialog ("\"" & checkDateChoice & "\":" & return & "Date specified is in the past..!" & return & "(delta: " & checkDate & ")") as string buttons {"OK"} default button 1 with icon 0
set blijfVragen to true
end if
on error
beep 2
tell application fappl to set myResult to display dialog ("\"" & checkDateChoice & "\":" & return & "Not a valid date specification.! ") as string buttons {"OK"} default button 1 with icon 0
set blijfVragen to true
end try
end if
if (TimeChoice as string) contains "hh:mm" then error "Not a valid time specification.! "
if character 2 of TimeChoice is not in "1234567890" then set TimeChoice to ("0" & TimeChoice) as string
try
if not blijfVragen then return {EventChoice, OccurrenceChoice, DateChoice & " " & TimeChoice, PasswChoice, PassRemChoice}
on error theErr -- will be mentioned in header
beep
try
if number of characters of theErr > 35 then ¬
set theErr to text 1 thru 35 of theErr
set theErr to "» " & theErr & return
end try
end try
end repeat
end repeat
end getBetterChoose
on getMonthNum(mth)
set monthNames to "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec"
set counter to 0
repeat
set counter to counter + 1
if word counter of monthNames is in mth then
set monthNum to counter
exit repeat
end if
end repeat
return monthNum
end getMonthNum