Create Calendar Event using linkable addressbook URL

I want to script an addressbook URL from the Contacts app into a Calendar Event, in which an addressbook URL link from the Contacts app is accessible on both OS X and iOS platforms. My current AppleScript creates an addressbook URL in an OS X calendar event, which the OS X Calendar app shows as a clickable link, with user interface words of

Show in Contacts…

The iOS calendar app, however, shows a link with the full text of link such as

addressbook://…(Contacts’ id for the person)

When the iphone link is clicked or pressed, the iPhone displays a menu with the option to

Open

Clicking on this Open option, however, yields no visible result and fails to show the contact such as occurs on OS X.

I have also attempted to use Nigel Garvey’s method to retrieve information from Objective C’s Contacts framework.

Nigel Garvey’s method to retrieve existing contact information using Contacts Framework

This method, however, yielded the same addressbook URL link as the Applescript accessing the OS X Contacts app.

  1. I would like to know how to write a contact URL that is linkable in both in OSX and iOS.

  2. If an addressbook URL is local to a device, or if OSX addressbook URLs are assigned differently than iOS URLs, what might be unifying methods via iCloud, frameworks, or shortcuts to create a more universal contact link?

My script:

# Designed to run when a specific contact is selected in the OS X contact app. 
# Creates a Calendar event using data from the selected contact. 
# Arbitrarily creates a new event lasting 15 minutes to start 24 hours, after its creation.
# https://www.macscripter.net/t/create-calendar-event-using-linkable-addressbook-url/75518

tell application "Contacts"
	repeat with thisPerson in (selection as list)
		tell thisPerson
			set ContactName to its name
			set phoneList to its phones
			set ContactUID to its id
		end tell
		set ContactURL to "addressbook://" & ContactUID
		set ContactPhone to missing value -- if no contact phone is found
		if (count of phoneList) is 1 then
			set ContactPhone to the value of first item of phoneList
		else
			set LabelNameList to {"iphone", "Mobile"}
			repeat with LabelName in LabelNameList
				set everyPhone to (every phone of thisPerson whose label contains LabelName)
				if everyPhone is not {} then
					set ContactPhone to (the value of first item of everyPhone)
					exit repeat
				end if
			end repeat
		end if
		
		(my CreateCalendarEvent:space ContactName:ContactName ContactPhone:ContactPhone ContactURL:ContactURL)
	end repeat
end tell


on CreateCalendarEvent:space ContactName:ContactName ContactPhone:ContactPhone ContactURL:ContactURL
	set TargetDate to (current date) + (24 * hours)
	set triggerInterval to -30
	set Duration to 15 * minutes
	set CalendarName to "Home"
	tell application "Calendar"
		tell calendar CalendarName
			set newEvent to make new event at end with properties {summary:"Call " & ContactName, start date:TargetDate, end date:(TargetDate + Duration), description:ContactPhone, url:ContactURL}
			set theAlarm to make new sound alarm at end of sound alarms of newEvent with properties {trigger interval:triggerInterval, sound name:"Sosumi"}
			make new display alarm at end of display alarms of newEvent with properties {trigger interval:triggerInterval}
			
			view calendar at TargetDate
			switch view to day view
			show newEvent
		end tell
	end tell
end CreateCalendarEvent:ContactName:ContactPhone:ContactURL:
1 Like