Add date to Fantastical title

I wanted to include the event date in my Fantastical event titles (useful for repeating events) so modified the script:

…
set theItem to item 1 of theItems

set theDate to start date of theItem
set theYearString to year of theDate as text
set theMonthString to (month of theDate as integer) as string
if (the length of theMonthString is 1) then set theMonthString to "0" & theMonthString
set theDayString to day of theDate as text
if (the length of theDayString is 1) then set theDayString to "0" & theDayString
set theDateString to theYearString & "-" & theMonthString & "-" & theDayString

set theTitle to (title of theItem) & " β€” " & theDateString
set theUrl to showURL of theItem
…
2 Likes

Thank you, @stevelw, for sharing this!

Do you happen to use Todoist in Fantastical? This also works for tasks synced from Todoist to Fantastical. Further, I tried to modify the script to include also time information in the title. However, the following script works for ordinary calendar events, but not for tasks synced from Todoist.

tell application "Fantastical"
	
	set theItems to selected calendar items
	if theItems is not equal to {} then
		
		set theItem to item 1 of theItems
        set theDate to start date of theItem

        set theYearString to year of theDate as text
        set theMonthString to (month of theDate as integer) as string
        if (the length of theMonthString is 1) then set theMonthString to "0" & theMonthString
        set theDayString to day of theDate as text
        if (the length of theDayString is 1) then set theDayString to "0" & theDayString

		set theHourString to hours of theDate as text
		if (the length of theHourString is 1) then set theHourString to "0" & theHourString
		set theMinuteString to minutes of theDate as text
		if (the length of theMinuteString is 1) then set theMinuteString to "0" & theMinuteString

        set theDateString to theYearString & "-" & theMonthString & "-" & theDayString & " at " & theHourString & ":" & theMinuteString

        set theTitle to (title of theItem) & " - " & theDateString
        set theUrl to showURL of theItem
		
		return "[" & theTitle & "](" & theUrl & ")"
	end if
	
end tell

Moreover, is it possible to distinguish all-day calendar events from events that starts on a specific time? Specifically, one includes only the date in the title, if it is the former case; one include both date and time, if it is the latter case.

Sorry, I don’t know the answer off the top of my head.

1 Like

I received replies from Fantastical related to Todoist in Fantastical.

Regarding the first point, there are some bugs with Todoist in Fantastical, and they have fixed it for the next release.

Regarding the second point, it seems that Fantastical revealed not so many variables to access for now, but they said that they are looking into reveal more variables.

The following is what we have access to Fantastical now:

calendar item n : This class represents an event.
id (text) : The unique identifier of the item.
title (text) : The event title.
location (text) : The event location.
start date (date) : The event start date.
end date (date) : The event end date.
notes (text) : The event notes.
URL (text) : The related URL for the event.
showURL (text) : The show URL for the event. When clicked or entered
into a browser, it pulls up the element in Fantastical.
1 Like

Thanks for the inside info, @Wen. Much appreciated !

With version 3.4.4 of Fantastical, the issue above has been resolved. Here is a slightly updated script that distinguishes all-day events:

tell application "Fantastical"
	
	set theItems to selected calendar items
	if theItems is not equal to {} then
		
		set theItem to item 1 of theItems
		set theDate to start date of theItem
		
		set theYearString to year of theDate as text
		set theMonthString to (month of theDate as integer) as string
		if (the length of theMonthString is 1) then set theMonthString to "0" & theMonthString
		set theDayString to day of theDate as text
		if (the length of theDayString is 1) then set theDayString to "0" & theDayString
		
		set theHourString to hours of theDate as text
		if (the length of theHourString is 1) then set theHourString to "0" & theHourString
		set theMinuteString to minutes of theDate as text
		if (the length of theMinuteString is 1) then set theMinuteString to "0" & theMinuteString
		
		if (theItem is isAllDay) then
			set theDateString to theYearString & "-" & theMonthString & "-" & theDayString
		else
			set theDateString to theYearString & "-" & theMonthString & "-" & theDayString & " at " & theHourString & ":" & theMinuteString
		end if
		
		set theTitle to (title of theItem) & " πŸ—“ " & theDateString
		set theUrl to showURL of theItem
		
		return "[" & theTitle & "](" & theUrl & ")"
	end if
	
end tell
1 Like