Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.6: Create iCal event from dates in Safari Apps
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.
    •    
  • Currently 3.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (16 votes cast)
 
[16,009 views]  

10.6: Create iCal event from dates in Safari | 4 comments | Create New Account
Click here to return to the '10.6: Create iCal event from dates in Safari' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.6: Create iCal event from dates in Safari
Authored by: mr. applescript on Oct 12, '09 09:42:46AM
You can retrieve the dates from text selected in Safari or any other application that supports Services using an Automator action posted on www.macosxautomation.com. There are two text filtering actions here:http://www.macosxautomation.com/services/download/actions.html Get URLs from Text and Get Dates from Text. Retrieved dates will be in UNIX format which can be converted to AppleScript date records fairly easily. -- ENJOY!

[ Reply to This | # ]
10.6: Create iCal event from dates in Safari
Authored by: paul7 on Oct 24, '09 11:00:16PM

Unfortunately, this Automator Service doesn't work if the date doesn't include a year. You will get an error. If you use the "Get Dates from Text" action from www.macosxautomation.com you will at least get an iCal event, but the date will be wrong, and you'll get a year like "0002".



[ Reply to This | # ]
10.6: Create iCal event from dates in Safari
Authored by: Jaime Gago on Jan 20, '10 02:01:42PM

That's cool, I finally have my right click "add date to iCal" from a web page, it's very unfortunate it only works if there is a year in the date though...There might be a way to default to the current year within the Script so at least you don't get an error.
It'd be nice though Apple builds this feature into Safari as it is in Mail. The Automator Service version of the Date pattern detector apparently doesn't work as well as the one in Mail.

Edited on Jan 20, '10 02:03:19PM by Jaime Gago



[ Reply to This | # ]
10.6: Create iCal event from dates in Safari
Authored by: PizzaCake on Jun 23, '11 05:42:00AM
Thanks, I had to amend the code to handle the odd situation where dates and times on eBay are not space separated and setting an alarm.

on run {input, parameters}
	set eventDate to (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
	if eventUrl contains "ebay.co" then
		set eventDateCleaned to items 1 thru 6 of eventDate as text
		set eventDateCleaned to eventDateCleaned & (items 8 thru 12 of eventDate as text)
		set eventDateCleaned to eventDateCleaned & space & (items 13 thru 20 of eventDate as text)
		set eventDate to date (eventDateCleaned)
	else
		set eventDate to date (input as text)
	end if
	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 - 30 * minutes, end date:eventDate}
			tell newEvent
				make new sound alarm at end of sound alarms with properties {trigger interval:0, sound name:"Submarine"}
			end tell
			show newEvent
		end tell
	end tell
end run


[ Reply to This | # ]