Time Block Reminders tasks in Calendar
To assist in the completion of tasks I find that by making a Time Block in my Calendar to focus on the issue makes it more likely I will actually complete the task š.
This Applescript will enable you to select a Reminder due Today, This Week or All then create an Event in Apple Calendar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################## | |
# Title: | |
############################################## | |
# Iain Dunn | |
# Logic2Design | |
# www.logic2design.com | |
# logic2design@icloud.com | |
# Last update: 26 January 2022 | |
# Version: 3 - added Calendar List option | |
# Contributors and sources | |
# http://www.michaelkummer.com/2014/03/18/how-to-create-a-reminder-from-an-e-mail/ | |
############################################## | |
# Configuration | |
############################################## | |
#Add the Calendars that you want to schedule, if disabled you will be prompted with a list of all Calendars | |
set the Calender_Lists to {"Business", "Finance", "Personal", "Recreation", "Work"} | |
set defaultCalendar to "Personal" -- select your default calendar | |
set defaultReminderTime to "9" | |
set defaultReminder to "Today" | |
############################################## | |
# Code | |
############################################## | |
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 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 | |
tell application "Calendar" | |
activate | |
-- Check to see if Default Calendars are set | |
try | |
Calender_Lists | |
on error errmsg number num | |
if num is -2753 then | |
set {Calender_Lists} to {name} of every calendar | |
end if | |
end try | |
(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 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 |
Comments
Post a Comment