Setting EventKit event URL

Although the Calendar Application will create a new event with a url, if Calendar creates that event, it will not edit that event to associate a url if EventKit created it. Likewise I cannot script EventKit, via Shane’s CalendarLib EC to create an event with a url property and value.

Creating an event and associating a url with it in AppleScript works without error.


use scripting additions
tell application "Finder"
	set Finder_Selection to selection as alias
	set Finder_Item_Name to name of Finder_Selection
	set Finder_URL to URL of Finder_Selection
end tell
set theSummary to Finder_Item_Name
set theDescription to "To Do" 
set d1 to current date
set d2 to d1 + 1 * hours
tell application "Calendar"
	tell calendar "Work"
		--delete (every event whose summary is theName)
		set theEvent to make new event with properties {start date:d1, allday event:true, summary:theSummary, url:Finder_URL, description:theDescription}
		activate
		show theEvent
	end tell
end tell

However, when I script EventKit via Shane’s CalendarLib EC to create an event, I cannot find a method to set a url to that event, and I cannot find a manner in which the Calendar Application can edit that event to set a file url.


use scripting additions
use framework "Foundation"
use script "CalendarLib EC"
tell application "Finder"
	set Finder_Selection to selection as alias
	set Finder_Item_Name to name of Finder_Selection
	set Finder_URL to URL of Finder_Selection
end tell
set theSummary to Finder_Item_Name
set theDescription to "To Do" 

set d1 to current date
set d2 to d1 + 1 * hours

set theStore to fetch store
set theCal to fetch calendar "Work" cal type cal cloud event store theStore
set theEvent to create event event store theStore ¬
	destination calendar theCal ¬
	event summary theSummary ¬
	starting date d1 ¬
	ending date d2 ¬
	event location "Office" event description theDescription ¬
	without runs all day
store event event theEvent event store theStore
--I cannot find a method to define an event URL via Shane's CalendarLib EC or via Objective C, or a method to convert the EventKit output into an event that Calendar recognizes.

tell application "Calendar"
	tell event theEvent
		set its url to Finder_URL --> errors
	end tell
end tell
--application "Calendar" errs.

I think that the second script errs as it fails to convert the EventKit output into a Calendar Application event id.

I have 3 questions.

  1. Does an event created by EventKit or Shane’s CalendarLib EC possess a url property?
  2. If so, what is the method to have Shane’s CalendarLib EC, or EventKit on its own, set that event url property to a file location?
  3. If not, what is the method to convert the EventKit output into an identifiable event that the Calendar Application can recognize?

Model: MacBook Pro
AppleScript: 2.5
Browser: Safari 600.5.17
Operating System: Mac OS X (10.10)

Yes.

use scripting additions
use framework "Foundation"
use script "CalendarLib EC"
tell application "Finder"
	set Finder_Selection to selection as alias
	set Finder_Item_Name to name of Finder_Selection
end tell
set theSummary to Finder_Item_Name
set theDescription to "To Do"

set d1 to current date
set d2 to d1 + 1 * hours

set theStore to fetch store
set theCal to fetch calendar "Work" cal type cal cloud event store theStore
set theEvent to create event event store theStore ¬
	destination calendar theCal ¬
	event summary theSummary ¬
	starting date d1 ¬
	ending date d2 ¬
	event location "Office" event description theDescription ¬
	without runs all day
set theURL to current application's |NSURL|'s fileURLWithPath:(POSIX path of Finder_Selection)
theEvent's setURL:theURL
store event event theEvent event store theStore

An event’s external_event_ID will match the ID used in Calendar.app. So modifying the above:

use scripting additions
use framework "Foundation"
use script "CalendarLib EC"
tell application "Finder"
	set Finder_Selection to selection as alias
	set Finder_Item_Name to name of Finder_Selection
end tell
set theSummary to Finder_Item_Name
set theDescription to "To Do"

set d1 to current date
set d2 to d1 + 1 * hours

set theStore to fetch store
set theCal to fetch calendar "Work" cal type cal cloud event store theStore
set theEvent to create event event store theStore ¬
	destination calendar theCal ¬
	event summary theSummary ¬
	starting date d1 ¬
	ending date d2 ¬
	event location "Office" event description theDescription ¬
	without runs all day
set theURL to current application's |NSURL|'s fileURLWithPath:(POSIX path of Finder_Selection)
theEvent's setURL:theURL
set theDesc to event info for event theEvent
set theID to event_external_ID of theDesc
store event event theEvent event store theStore

tell application id "com.apple.iCal" -- Calendar
	set theProps to properties of event id theID of (last calendar whose name is "Work")
end tell

Thank you for simplifying the problem :slight_smile: