Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This will allow you to select a Reminder then schedule an Event in Apple Calendar so you can block off time to undertake the task.
############################################################
# Title: Reminders to Calendar - Time Block
############################################################
#Logic2design.com
#logic2design@icloud.com
# Last update: 2021-06-06
# Version: 2
# Contributors and sources
# http://www.michaelkummer.com/2014/03/18/how-to-create-a-reminder-from-an-e-mail/
############################################################
# Configuration
############################################################
set the Calender_Lists to {"Personal", "Work", "Business", "Google"} -- Add the Calendars that you want to schedule
set defaultCalendar to "Personal"
############################################################
# Code
############################################################
set defaultReminderTime to "9"
set defaultReminder to "Today"
set now to (current date)
set today to now - (time of now)
set tomorrow to (today) + (24 * 60 * 60)
set thisWeek to (current date) + (7 * days)
tell application "Reminders"
activate
set theButton to button returned of (display dialog "Do you want to create an event for a Reminder due today, this week or all open" with title "Select ToDo" buttons {"Today", "Due This Week", "All Open"} default button 1)
if theButton is "Today" then
set inboxToDos to every reminder whose due date is less than tomorrow and completed is false
else if theButton is "Due This Week" then
set inboxToDos to every reminder whose due date is less than thisWeek and completed is false
else
set inboxToDos to every reminder whose completed is false
end if
set scheduleToDo to {}
repeat with r from 1 to length of inboxToDos
set this_todo to item r of inboxToDos
set todoName to (get name of this_todo) as text
copy (todoName) to end of scheduleToDo
end repeat
if scheduleToDo is not {} then
set todoList to choose from list scheduleToDo with prompt "Select the Reminder to Schedule"
else
display dialog "There are no Reminders to Schedule" buttons {"OK"}
return
end if
if todoList is false then return
set todoSelect to every reminder whose name is equal to todoList and completed is false
repeat with r from 1 to length of todoSelect
set this_todo to item r of todoSelect
--set eventList to (get list of this_todo)
set eventName to (get name of this_todo) as text
--set eventTags to (get tag names of this_todo) as text
set eventURL to (get id of this_todo) as text
set eventDue to (get due date of this_todo) as text
set eventNotes to (get body of this_todo) as text
set inputTextNotes to eventNotes
set findTextNotes to "missing value"
set replaceTextNotes to ""
set newNotes to do shell script "sed 's|" & quoted form of "" & findTextNotes & "" & "|" & quoted form of replaceTextNotes & "|g' <<< " & quoted form of inputTextNotes
set inputTextDue to eventDue
set findTextDue to "missing value"
set replaceTextDue to ""
set newDue to do shell script "sed 's|" & quoted form of "" & findTextDue & "" & "|" & quoted form of replaceTextDue & "|g' <<< " & quoted form of inputTextDue
set inputTextURL to eventURL
set findTextURL to "x-apple-reminder://"
set replaceTextURL to "x-apple-reminderkit://REMCDReminder/"
set newURL to do shell script "sed 's|" & quoted form of findTextURL & "|" & quoted form of replaceTextURL & "|g' <<< " & quoted form of inputTextURL
end repeat
tell me to activate
# Set Followup Date/Time
(choose from list {"2 Hours", "Today", "Tonight", "Tomorrow", "2 Days", "3 Days", "4 Days", "5 Days", "6 Days", "1 Week", "Saturday", "Sunday", "Next Monday"} default items defaultReminder OK button name "Select" with prompt "Set Event time" with title "Time Block Reminder")
set reminderDate to result as text
# exit if user clicks Cancel or Escape
if reminderDate is "false" then return
# for all the other options, calculate the date based on the current date
--set remindMeDate to my chooseRemindMeDate(reminderDate)
set theStartDate to my chooseRemindMeDate(reminderDate)
if reminderDate is "2 Hours" then
set defaultReminderTime to 0
else if reminderDate is "Tonight" then
defaultReminderTime
else
set defaultReminderTime to text returned of (display dialog "what time do you want to start? (Answer in decimal ie 2:30pm is 14.5)" default answer "9")
end if
--set defaultReminderTime to text returned of (display dialog "what time do you want to start? (answer in decimal ie 8:30 is 8.5)" default answer "9")
# set the time for on the reminder
if reminderDate is "2 Hours" then
set theStartDate to (current date) + 2 * hours
else if reminderDate is "Tonight" then
set time of theStartDate to 60 * 60 * 17
else
set time of theStartDate to 60 * 60 * defaultReminderTime
end if
display dialog "How long is the Event? (minutes) " default answer 30
set appt_length to text returned of result
if appt_length < 1 then
set appt_mins to (0)
set theEndDate to theStartDate + (appt_mins * minutes)
set allDay to true
else
set appt_mins to (appt_length)
set theEndDate to theStartDate + (appt_mins * minutes)
set allDay to false
end if
(choose from list Calender_Lists default items defaultCalendar OK button name "Select" with prompt "Pick Calendar" with title "Create Calendar Event")
set Cal to result as text
tell application "Calendar"
tell calendar Cal
make new event with properties {summary:"Reminder - " & eventName, start date:theStartDate, end date:theEndDate, description:"Due Date -" & newDue & return & newNotes, url:newURL}
end tell
end tell
end tell
#################################################################################
# Functions
#################################################################################
# date calculation with the selection from the dialogue
# use to set the scheduled date
on chooseRemindMeDate(selectedDate)
if selectedDate = "2 Hours" then
set remindMeDate to (current date) + 0 * days
--(current date) + 2 * hours
--set time of remindMeDate to 120 * minutes
else if selectedDate = "Today" then
set remindMeDate to (current date) + 0 * days
else if selectedDate = "Tonight" then
set remindMeDate to (current date) + 0 * days
--set time of remindMeDate to 60 * 60 * 17
else if selectedDate = "Tomorrow" then
set remindMeDate to (current date) + 1 * days
else if selectedDate = "2 Days" then
set remindMeDate to (current date) + 2 * days
else if selectedDate = "3 Days" then
set remindMeDate to (current date) + 3 * days
else if selectedDate = "4 Days" then
set remindMeDate to (current date) + 4 * days
else if selectedDate = "5 Days" then
set remindMeDate to (current date) + 5 * days
else if selectedDate = "6 Days" then
set remindMeDate to (current date) + 6 * days
else if selectedDate = "Saturday" then
# get the current day of the week
set curWeekDay to weekday of (current date) as string
if curWeekDay = "Monday" then
set remindMeDate to (current date) + 5 * days
else if curWeekDay = "Tuesday" then
set remindMeDate to (current date) + 4 * days
else if curWeekDay = "Wednesday" then
set remindMeDate to (current date) + 3 * days
# if it's Thursday, I'll set the reminder for Friday
else if curWeekDay = "Thursday" then
set remindMeDate to (current date) + 2 * days
# if it's Friday I'll set the reminder for Thursday next week
else if curWeekDay = "Friday" then
set remindMeDate to (current date) + 1 * days
else if curWeekDay = "Saturday" then
set remindMeDate to (current date) + 7 * days
else if curWeekDay = "Sunday" then
set remindMeDate to (current date) + 8 * days
end if
else if selectedDate = "Sunday" then
# end of week means Sunday in terms of reminders
# get the current day of the week
set curWeekDay to weekday of (current date) as string
if curWeekDay = "Monday" then
set remindMeDate to (current date) + 6 * days
else if curWeekDay = "Tuesday" then
set remindMeDate to (current date) + 5 * days
else if curWeekDay = "Wednesday" then
set remindMeDate to (current date) + 4 * days
# if it's Thursday, I'll set the reminder for Friday
else if curWeekDay = "Thursday" then
set remindMeDate to (current date) + 3 * days
# if it's Friday I'll set the reminder for Thursday next week
else if curWeekDay = "Friday" then
set remindMeDate to (current date) + 2 * days
else if curWeekDay = "Saturday" then
set remindMeDate to (current date) + 1 * days
else if curWeekDay = "Sunday" then
set remindMeDate to (current date) + 7 * days
end if
else if selectedDate = "Next Monday" then
set curWeekDay to weekday of (current date) as string
if curWeekDay = "Monday" then
set remindMeDate to (current date) + 7 * days
else if curWeekDay = "Tuesday" then
set remindMeDate to (current date) + 6 * days
else if curWeekDay = "Wednesday" then
set remindMeDate to (current date) + 5 * days
else if curWeekDay = "Thursday" then
set remindMeDate to (current date) + 4 * days
else if curWeekDay = "Friday" then
set remindMeDate to (current date) + 3 * days
else if curWeekDay = "Saturday" then
set remindMeDate to (current date) + 2 * days
else if curWeekDay = "Sunday" then
set remindMeDate to (current date) + 1 * days
end if
else if selectedDate = "1 Week" then
set remindMeDate to (current date) + 7 * days
end if
return remindMeDate
end chooseRemindMeDate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment