Create Calendar Event from Email on Mac w/ Notes and URL

Is there a reliable way to drag or otherwise create a calendar event from an email message with:

  • Email subject is event title
  • Email body in event notes
  • Link to the email message in the URL field

Dragging will give me the title and URL without notes, which I can copy/paste. Siri suggestions or clicking on the dropdown that appears next to a date in the text when you hover over it gives me mixed results.

Thanks

1 Like

Hi,

Here is something I knocked up for you, though I warn you I have been up since 2:00am for the Apple event :grinning:

The Github link is https://gist.github.com/logic2design/74df149adae7ec50b41ecee904b54c0d

Cheers

Iain

#################################################################################
# Title: Create Calendar Event from eMail 
#################################################################################

# Iain Dunn
# Logic2design.com
# logic2design@icloud.com

## v2 - Default Date&Time

#################################################################################
# Configuration
#################################################################################

#Set Current Date & Time
set todayDate to current date
set eventDate to short date string of todayDate as text
set eventTime to (do shell script "date +\"%l:%M %p\" | awk '{$1=$1;print}'")

#Event Time
display dialog "When is the Event" default answer eventDate & " " & eventTime
set theStartDate to date (text returned of result)

display dialog "How long is the Event? (minutes)" default answer 30
set appt_length to text returned of result
set appt_mins to (appt_length)
set theEndDate to theStartDate + (appt_mins * minutes)

#################################################################################
# Script
#################################################################################

#get eMail
tell application "Mail"
	set theSelection to selection as list
	# do nothing if no email is selected in Mail
	try
		set theMessage to item 1 of theSelection
	on error
		return
	end try
	
	set theSummary to theMessage's subject
	set theDescription to theMessage's content
	set theOrigMessageId to theMessage's message id
	set theUrl to {"message:%3C" & my replaceText(theOrigMessageId, "%", "%25") & "%3E"}
end tell

#select Calendar
tell application "Calendar"
	set clist to name of calendars
	set cname to choose from list clist with prompt "Select Calendar"
	set cal to cname as text
	
end tell

#Create Event
tell application "Calendar"
	tell calendar cal
		make new event with properties {summary:theSummary, description:theDescription, url:theUrl, start date:theStartDate, end date:theEndDate}
	end tell
end tell

tell application "Calendar" to activate
#################################################################################
# Functions
#################################################################################

# string replace function
# used to replace % with %25
on replaceText(subject, find, replace)
	set prevTIDs to text item delimiters of AppleScript
	set text item delimiters of AppleScript to find
	set subject to text items of subject
	
	set text item delimiters of AppleScript to replace
	set subject to "" & subject
	set text item delimiters of AppleScript to prevTIDs
	
	return subject
end replaceText

Hey that’s really cool! Thanks for taking the time. I fired it off as a test and it worked. I’ll take a look at the prompts and see what I can learn.

Thanks again!

No worries, I am glad it helped you out.

I tweaked the code to allow you to set an AllDay event.

Iain

1 Like