Add a Fantastical 2 item for the current document

This simplistic script will populate the entry dialog of Fantastical 2 with the name of the currently selected item in DEVONthink and, optionally, the item link of that item. Select an item and run the script. (I install this script in my toolbar for easy access.) A dialog will open with the item name and optional item link. Fantastical uses a plain language parser so change the dialog content in whatever way you wish in order to prime the Fantastical entry. The dialog lets you choose whether to add the entry immediately to Fantastical 2, or to open Fantastical 2’s menu bar dialog so you can adjust other Fantastical 2 options if you wish. The addition of the item link is controlled by the “itemLink” property which is “true” by default – meaning the link is part of the proposed calendar entry. With the link then you can click the URL field in the calendar and open that document in DEVONthink.

I have configured Fantastical 2 to sync calendars and reminders with BusyCal and Apple Calendar – so what happens in Fantastical 2 happens every where.

This is provided as is and support is probably not going to happen :confused:

property itemLink : true -- when true: include the DEVONthink item link (reference URL)

tell application id "DNtp" -- DEVONthink
		set theSelection to the first item of (the selection as list)
		if theSelection is {} then error "Please select something"
		set theName to the name of the theSelection
		if itemLink then
			set theURL to " " & the reference URL of theSelection
			set theURL to ""
		end if
		set theString to theName & theURL
		set theResult to (display dialog "Edit the following if you wish" default answer theString buttons {"Add immediately", "Open in Fantastical", "Cancel"} default button 3 cancel button 3 with title "Create a Fantastical 2 entry")
		set theText to text returned of theResult
		set theButton to button returned of theResult
		tell application id "fCl2" -- Fantastical 2
			if theButton is "Add immediately" then parse sentence theText with add immediately
			if theButton is "Open in Fantastical" then parse sentence theText
		end tell
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink Pro" message error_message as warning
	end try
end tell

Here is the script’s dialog, on the left, and the Fantastical 2 dialog on the right. Fantastical 2 parses entries and figures out what to do. Please read Fantastical 2’s help and tutorials if you need to figure how to use that program.

Nice. Thanks, korm. :smiley:

Nicely done-thanks!

I added the script to DEVONthink’s script menu, Reminders as I don’t use toolbars in DEVONthink. The script also works fine when called by a Keyboard Maestro macro.

When the user selects the option to open the entry in Fantastical, one can change the item from a calendar entry to a task. Assuming the user syncs Fantastical tasks to iCloud, this allows the korm’s script to do the work of the two DEVONthink scripts (Add as Event to Calendar & Add as To Do in Reminders). If one will be using this script to create tasks (Reminders), it might be helpful to modify the script to add the URL to the Notes field as Reminders do not have a URL field. As example:

if theButton is "Open in Fantastical" then parse sentence theText notes theURL

The downside to this is that calendar entries will have the DEVONthink URL link in both the URL and the note fields.

As usual, all links will work on iOS when the documents are also synced to DEVONthink to Go.

Going one step further, users of Cultured Code’s Things app can use the script to add a task to a Reminders list that is monitored by Thing’s Inbox, making yet another DEVONthink Reminder script redundant.

Thanks for the tips, Greg. Because Fantastical 2 plays very well with Apple Calendar and Reminders on every platform, it makes a great hub for syncing data with other apps, as you pointed out.

I intentionally made the dialog field contain minimal info: the document (or group) name and its DEVONthink URL. I had experimented with the “notes” cue as you mentioned; and decided I would rather not de-dupe every Fantastical 2 entry.

Flexibits has some tutorials and other info that help explain the sentences it understands – which you can use in the dialog box that the script shows you.

(BTW: there is a Fantastical 2 Action Extension that will populate the Fantastical 2 menu with text selected in an app – just the text.)