Last active
July 6, 2023 14:58
-
-
Save logic2design/a8e279ec4c51274ced15ae6930beaaff to your computer and use it in GitHub Desktop.
This workflow will let you chose a Things 3 task to add to your selected Calendar so time can be blocked out to address the task.
This file contains hidden or 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: Things3 To Calendar - Time Block | |
############################################## | |
# Iain Dunn | |
# Logic2Design | |
# www.logic2design.com | |
# Last update: 26-01-2022 | |
# Version: 4 | |
# Contributors and sources | |
# Michael Kummer michaelkummer.com | |
############################################## | |
# 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" | |
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) | |
set the Calender_Lists to {"Personal", "Work", "Business", "Google"} | |
tell application "Things3" | |
set scheduleList to {} | |
#Choose the type of To Do to Schedule | |
set theButton to button returned of (display dialog "Do you want to create an event for a ToDo 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 to do of list "Today" --or every to do whose status is open and due date is less than tomorrow | |
else if theButton is "Due This Week" then | |
set inboxToDos to (every to do whose status is open and due date is less than thisWeek) & (every to do of list "Today") | |
else | |
set inboxToDos to every to do whose status is open | |
end if | |
# Select the To Do | |
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 | |
if scheduleToDo does not contain todoName then copy (todoName) to end of scheduleToDo -- removes duplicates | |
end repeat | |
if scheduleToDo is not {} then | |
set todoList to choose from list scheduleToDo with prompt "Select the ToDo to Schedule" | |
else | |
display dialog "There are no ToDos to Schedule" buttons {"OK"} | |
return | |
end if | |
if todoList is false then return | |
set todoSelect to every to do whose name is equal to todoList | |
repeat with r from 1 to length of todoSelect | |
set this_todo to item r of todoSelect | |
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 notes of this_todo) as text | |
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 ToDo") | |
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 date | |
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) | |
Set to 0 for an all day event" 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 | |
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 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:"Things3 - " & eventTags & " - " & eventName, start date:theStartDate, end date:theEndDate, description:"Due Date -" & eventDue & return & eventNotes, url:"things:///show?id=%22" & eventURL & "%22", allday event:allDay} | |
end tell | |
end tell | |
end tell | |
############################################## | |
# Functions | |
############################################## | |
# date calculation with the selection from the dialogue | |
# use to set the initial and the re-scheduled date | |
on chooseRemindMeDate(selectedDate) | |
if selectedDate = "2 Hours" then | |
set remindMeDate to (current date) + 0 * days | |
else if selectedDate = "Tonight" then | |
set remindMeDate to (current date) + 0 * days | |
else if selectedDate = "Today" then | |
set remindMeDate to (current date) + 0 * days | |
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 = "1 Week" then | |
set remindMeDate to (current date) + 7 * 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 | |
end if | |
return remindMeDate | |
end chooseRemindMeDate |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment