Wednesday, August 29, 2012

Create Reminder in AppleScript with Intelligent Date Time Parsing

Although you can make a new reminder object in Mountain Lion's Reminders application directly with Apple Script you lose the cool built-in parsing that extracts the date/time settings.

For example we want to simply write "Bowling with Bob 6PM on Friday" and have Reminders parse out the date and time to create a reminder(name="Bowling with Bob", datetime="2012-09-01 18:00:00")

Here is the script, note that I have it in Alfred-friendly form since I use the Alfred app launcher:

on alfred_script(q)
try
  tell application "Reminders"
    activate
    activate -- Single activate doesn't always work, esp if Reminders is closed.
    show list "Reminders"
   
    tell application "System Events" to keystroke "n" using command down
    tell application "System Events" to keystroke q
    tell application "System Events" to key code 36 -- enter
  end tell
 
on error a number b
  display dialog a
end try
end alfred_script

-- how to call:
--alfred_script("Bowling with Bob 6PM on Friday")

No comments: