Reminders and AppleScript

Viticci wrote a great guide on using AppleScript to improve the standard Reminders.app that Apple provices on every Mac.

He ended his article with the following quote:

The downside of interacting with dialogs generated by OS X is that you can’t have the fancy custom interface of OmniFocus’ panel; you’re limited in the number of buttons you can add; and it’s moderately complex to customize the dialog window with additional options for things like notes or dates (which I have purposefully advoided to keep the script as simple as possible). If you’re looking for more advanced AppleScript solutions that work around natural language parsing for date and time, I’m sure you can find some online.

Since I liked the idea of a quick entry app, but need a due date for every today I create, I decided to tweak his script a little bit.

The app shows a standard Applescript dialog, but gives you the option to either create a reminder, or create a reminder with a due date. Choosing the later allows you to set a date and time for your reminder and an optional note.

-- 2014
-- Thomas Verschoren
-- Based on Script by Viticci
tell application "System Events"
    set reminder to display dialog "Create a new reminder" default answer "" buttons { "Cancel" , "No Due Date" , "Set Due Date" } with icon path to resource "Reminders.icns" in bundle ( path to application "Reminders" )
    set reminTitle to text returned of result
    set answer to button returned of reminder
    if answer is equal to "No Due Date" then
        set optNote to display dialog "Add a Note" default answer "" buttons { "Cancel" , "No Notes" , "Add Notes" } with icon path to resource "Reminders.icns" in bundle ( path to application "Reminders" )
        set reminNote to text returned of result
        set noteAnswer to button returned of optNote 
        if noteAnswer is "No Notes" then
            tell application "Reminders"
                set newremin to make new reminder
                set name of newremin to reminTitle
            end tell
        end if
        if noteAnswer is "Add Notes" then
            tell application "Reminders"
                set newremin to make new reminder
                set name of newremin to reminTitle
                set body of newremin to reminNote
            end tell
        end if
    end if
    if answer is equal to "Set Due Date" then
        set dueDate to display dialog "Due date" default answer "DD/MM/YYYY" buttons { "No Date" , "Set Date" } with icon path to resource "Reminders.icns" in bundle ( path to application "Reminders" )
        set reminDate to text returned of result
        set dateAnswer to button returned of dueDate 
        if dateAnswer is equal to "No Date" then
            set optNote to display dialog "Add a Note" default answer "" buttons { "Cancel" , "No Notes" , "Add Notes" } with icon path to resource "Reminders.icns" in bundle ( path to application "Reminders" )
            set reminNote to text returned of result
            set noteAnswer to button returned of optNote 
            if noteAnswer is "No Notes" then
                tell application "Reminders"
                    set newremin to make new reminder
                    set name of newremin to reminTitle
                end tell
            end if
            if noteAnswer is "Add Notes" then
                tell application "Reminders"
                    set newremin to make new reminder
                    set name of newremin to reminTitle
                    set body of newremin to reminNote
                end tell
            end if
        end if
        if dateAnswer is equal to "Set Date" then
            set dueTime to display dialog "Due hour" default answer "HH:MM" buttons { "No Time" , "Set Time" } with icon path to resource "Reminders.icns" in bundle ( path to application "Reminders" )
            set reminHour to text returned of result
            set timeAnswer to button returned of dueTime 
            if timeAnswer is "No Time" then
                set stringedDate to reminDate as string
                set optNote to display dialog "Add a Note" default answer "" buttons { "Cancel" , "No Notes" , "Add Notes" } with icon path to resource "Reminders.icns" in bundle ( path to application "Reminders" )
                set reminNote to text returned of result
                set noteAnswer to button returned of optNote 
                if noteAnswer is "No Notes" then
                    tell application "Reminders"
                        set newremin to make new reminder
                        set name of newremin to reminTitle
                        set due date of newremin to date stringedDate
                    end tell
                end if
                if noteAnswer is "Add Notes" then
                    tell application "Reminders"
                        set newremin to make new reminder
                        set name of newremin to reminTitle
                        set body of newremin to reminNote
                        set due date of newremin to date stringedDate
                    end tell
                end if
            end if
            if timeAnswer is "Set Time" then
                set stringedDate to reminDate as string
                set stringedHour to reminHour as string
                set stringedAll to stringedDate & " " & stringedHour
                set optNote to display dialog "Add a Note" default answer "" buttons { "Cancel" , "No Notes" , "Add Notes" } with icon path to resource "Reminders.icns" in bundle ( path to application "Reminders" )
                set reminNote to text returned of result
                set noteAnswer to button returned of optNote 
                if noteAnswer is "No Notes" then
                    tell application "Reminders"
                        set newremin to make new reminder
                        set name of newremin to reminTitle
                        set due date of newremin to date stringedAll
                    end tell
                end if
                if noteAnswer is "Add Notes" then
                    tell application "Reminders"
                        set newremin to make new reminder
                        set name of newremin to reminTitle
                        set body of newremin to reminNote
                        set due date of newremin to date stringedAll
                    end tell
                end if
            end if
        end if
    end if
end tell