set theBoolean to "True"
say "What Time Would You Like To Wake Up?" using "Alex"
set theTime to the text returned of (display dialog "What Time Would You Like To Wake Up?" default answer "6 30")
if the length of theTime is 1 then
set theHour to "0" & theTime as string
set theMinutes to "00" as string
else if the length of theTime is 2 then
set theHour to theTime as string
set theMinutes to "00" as string
else if the length of theTime is 3 then
set theHour to "0" & character 1 of theTime as string
set theMinutes to characters 2 thru 3 of theTime as string
else if the length of theTime is 4 then
set theHour to characters 1 thru 2 of theTime as string
set theMinutes to characters 3 thru 4 of theTime as string
else
say "That is an un known time" using "Alex"
say "You're alarm has not been set" using "Alex"
return
end if
if (theMinutes as integer) is greater than 60 then
say "That is an un known time!" using "Alex"
say "You're alarm has not been set!" using "Alex"
set theBoolean to "False"
return
end if
if (theHour as integer) is greater than 12 then
say "That is an un known hour!" using "Alex"
say "You're alarm has not been set!" using "Alex"
set theBoolean to "False"
return
end if
set theTime to theHour & ":" & theMinutes & ":00"
say "On which day?" using "Alex"
set theWeekday to the text returned of (display dialog "Which Day?" default answer "")
-- The Weekday of this week (may be before, after, or on today's date)
if theWeekday is equal to "Monday" then
set theDay to DateOfThisInstanceOfThisWeekdayBeforeOrAfterThisDate(current date, Monday, 0)
else if theWeekday is equal to "Tuesday" then
set theDay to DateOfThisInstanceOfThisWeekdayBeforeOrAfterThisDate(current date, Tuesday, 0)
else if theWeekday is equal to "Wednesday" then
set theDay to DateOfThisInstanceOfThisWeekdayBeforeOrAfterThisDate(current date, Wednesday, 0)
else if theWeekday is equal to "Thursday" then
set theDay to DateOfThisInstanceOfThisWeekdayBeforeOrAfterThisDate(current date, Thursday, 0)
else if theWeekday is equal to "Friday" then
set theDay to DateOfThisInstanceOfThisWeekdayBeforeOrAfterThisDate(current date, Friday, 0)
else if theWeekday is equal to "Saturday" then
set theDay to DateOfThisInstanceOfThisWeekdayBeforeOrAfterThisDate(current date, Saturday, 0)
else if theWeekday is equal to "Sunday" then
set theDay to DateOfThisInstanceOfThisWeekdayBeforeOrAfterThisDate(current date, Sunday, 0)
else
set theBoolean to false
say "That is an un known day!" using "Alex"
say "You're alarm has not been set!" using "Alex"
return
end if
say "Would you like me to wake you up in the morning? Or afternoon!" using "Alex"
set theAMPM to the text returned of (display dialog "AM or PM?" default answer "AM")
set theDayOfWeek to weekday of theDay as string
set theMonth to month of theDay as string
set theDayofTheMonth to day of theDay as integer
set theYear to year of theDay as integer
set theDate to (date (theDayOfWeek & ", " & theMonth & " " & theDayofTheMonth & ", " & theYear & " " & theTime & " " & theAMPM))
if theHour is equal to "01" then
set speakHour to "one"
else if theHour is equal to "02" then
set speakHour to "two"
else if theHour is equal to "03" then
set speakHour to "three"
else if theHour is equal to "04" then
set speakHour to "four"
else if theHour is equal to "05" then
set speakHour to "five"
else if theHour is equal to "06" then
set speakHour to "six"
else if theHour is equal to "07" then
set speakHour to "seven"
else if theHour is equal to "08" then
set speakHour to "eight"
else if theHour is equal to "09" then
set speakHour to "nine"
else if theHour is equal to "10" then
set speakHour to "ten"
else if theHour is equal to "11" then
set speakHour to "eleven"
else if theHour is equal to "12" then
set speakHour to "twelve"
end if
if theMinutes is equal to "00" then
set theMinutes to "Oh Clock"
end if
if theBoolean is not equal to "False" then
set theFile to "/Users/porter1/Desktop/Projects Jarvis/AppleScripts/goodMorningWeather.scpt"
tell application "Calendar"
set newEvent to make new event at end of events of calendar "Alarm" with properties {summary:"Alarm", start date:theDate}
set theAlarm to make new open file alarm at end of open file alarms of newEvent with properties {trigger interval:0, filepath:POSIX path of theFile}
end tell
if theAMPM is equal to "AM" then
say "Okay! I have set your alarm for, " & theDayOfWeek & " morning, " & " at " & speakHour & theMinutes using "Alex"
else
say "Okay! I have set your alarm for, " & theDayOfWeek & " afternoon, " & " at " & speakHour & theMinutes using "Alex"
end if
else
say "Your alarm has not been set" using "Alex"
end if
on DateOfThisInstanceOfThisWeekdayBeforeOrAfterThisDate(d, w, i) -- returns a date
-- Keep an note of whether the instance value *starts* as zero
set instanceIsZero to (i is 0)
-- Increment negative instances to compensate for the following subtraction loop
if i < 0 and d's weekday is not w then set i to i + 1
-- Subtract a day at a time until the required weekday is reached
repeat until d's weekday is w
set d to d - days
-- Increment an original zero instance to 1 if subtracting from Sunday into Saturday
if instanceIsZero and d's weekday is Saturday then set i to 1
end repeat
-- Add (adjusted instance) * weeks to the date just obtained and zero the time
d + i * weeks - (d's time)
end DateOfThisInstanceOfThisWeekdayBeforeOrAfterThisDate