10.6: Create iCal event from dates in Safari

Oct 12, '09 07:30:05AM

Contributed by: jaysoffian

I sometimes want to create an event in iCal from a date that appears on a web page I'm viewing in Safari. Using Automator, I created a Service to do just that.

Here's how:

  1. Launch Automator
  2. Select Service from the Choose a Template for your Workflow sheet.
  3. Set the drop-downs at the top of the Untitled service to 'Service receives selected' [dates] 'in' [Safari].
  4. Drag a Run AppleScript action to the top of the Untitled service.
  5. Replace the template text in the Run AppleScript action with the following:
    on run {input, parameters}
      set eventDate to date (input as text)
      tell application "Safari"
        set currentTab to current tab of first window
        set eventSummary to name of currentTab
        set eventUrl to URL of currentTab
      end tell
      tell application "iCal"
        activate
        tell calendar "Home"
          set newEvent to make new event at end of events with properties {summary:eventSummary, url:eventUrl, start date:eventDate, end date:eventDate + 30 * minutes}
          show newEvent
        end tell
      end tell
    end run
  6. In the AppleScript text above, replace Home with the name of the iCal calendar that you want to receive the new events.
  7. Save the service as New iCal Event from Date (or whatever you wish to call it).
You should now be able to select something resembling a date/time in Safari and run this Service via either the contextual menu or the Services menu. Note that the data detector for dates seems a bit more liberal than AppleScript at parsing dates, so you may sometimes get an AppleScript error when running this service.

Comments (4)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20090921113605560