Skip to content

Instantly share code, notes, and snippets.

@jsulak
Last active April 11, 2022 09:37
Show Gist options
  • Save jsulak/9cb7d2f476d155d0e9aea428f583b5b0 to your computer and use it in GitHub Desktop.
Save jsulak/9cb7d2f476d155d0e9aea428f583b5b0 to your computer and use it in GitHub Desktop.
Applescript to move tasks from Reminders.app to Omnifocus Inbox
-- Move everything in Reminders app to Omnifocus
tell application "Reminders"
repeat with theReminder in (get reminders in list "Reminders" whose completed is false)
with timeout of 120 seconds
set success to true
set the newName to (the name of theReminder) as string
set the dueDate to the due date of theReminder
if (body of theReminder) is not missing value then
set the reminderNotes to (body of theReminder) as text
else
set the reminderNotes to ""
end if
-- Create the inbox task
tell application "OmniFocus"
tell default document
set newTask to make new inbox task with properties {name:newName}
-- To make this a bit safer, we only want to keep the new Omnifocus task,
-- and delete the old reminders task, if insertion succeeds
try
tell newTask
set due date to dueDate
set note to reminderNotes
end tell
-- If this contains an agenda phrase, then set the context
if is_agenda(newName) of me then
set agendaContext to (first flattened context where its name = "Agenda")
set context of newTask to agendaContext
end if
-- If this is a dry cleaning task, then set the context
if is_dry_cleaning(newName) of me then
set dryCleaningContext to (first flattened context where its name = "Dry cleaning")
set context of newTask to dryCleaningContext
end if
on error errStr number errornumber
-- If there's an error, delete the omnifocus task
set success to false
delete newTask
log errStr
end try
end tell
end tell
-- If we've successfully added the task, then delete it from Reminders
if success then
-- log "success!!"
delete theReminder
end if
end timeout
end repeat
end tell
-- Parse task text to determine if it contains a key phrase
-- indicating that it is an agenda task
on is_agenda(taskText)
set agendaPhrases to {"talk to", "follow up", "ask "}
repeat with phrase in agendaPhrases
if phrase is in taskText then
return true
end if
end repeat
return false
end is_agenda
-- Parse task text to determine if it's a dry cleaning task
on is_dry_cleaning(taskText)
if taskText contains "dry cleaning" then
return true
end if
return false
end is_dry_cleaning
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment