Agenda integration with OmniFocus

I’ll work on the workflow more tomorrow. Interesting indeed!

Got it! Selected project in OmniFocus to New Project in Agenda — using Shortcuts and Omni Automation!

Includes: project title, project note, project due date, and project tags

Essentially it works like this:

  1. Omni Automation Script action returns a JSON dictionary containing the properites of the selected OmniFocus project
  2. The passed JSON dictionary is used to insert the various bits of data into the Agenda Shortcuts actions

Here’s the basic Shortcuts workflow:

And the Omni Automation script for the Omni Automation Script action:

(async () => {
	try {
		var sel = selection.projects
		if(sel.length === 1){
			var selectedItem = sel[0]
		} else {
			throw {
				name: "Selection Issue", 
				message: "Please select a single project."
			}
		}
		
		if (selectedItem.tags.length > 0){
			tagNames = selectedItem.tags.map(tag => tag.name)
			var tagNamesString = "#" + tagNames.join(" #")
		} else { var tagNamesString = "(NO TAGS)"}
		
		
		primaryKey = selectedItem.id.primaryKey
		projectLink = `omnifocus:///task/${primaryKey}`
		projectNote = (selectedItem.note) ? selectedItem.note : "(NO NOTE)"
		projectDueDate = (selectedItem.dueDate) ? selectedItem.dueDate.toISOString(): ""
		var itemProperties = new Object()
		itemProperties["projectTitle"] = selectedItem.name
		itemProperties["projectLink"] = projectLink
		itemProperties["projectNote"] = projectNote
		itemProperties["projectDueDate"] = projectDueDate
		itemProperties["tagNamesString"] = tagNamesString		
		itemProperties["noteTitle"] = selectedItem.name

		return JSON.stringify(itemProperties)
	}
	catch(err){
		if(!err.message.includes("cancelled")){
			await new Alert(err.name, err.message).show()
		}
		throw `${err.name}\n${err.message}`
	}
})();
1 Like

On my machine I only have OmniFocus 4 installed so it won’t help to send you a link to a shortcut. You’ll have to recreate the workflow. The tricky part is making sure the correct dataKey is used for each of the variable insertions. Be sure to add it to the “Get Value for Key” field that appers when you click on the placed variable instance:

FYI, here’s the source project in OmniFocus:

2 Likes

Wow. You just made my day. It would have taken me months to do this; if ever. :pray::pray:

1 Like

@Otto-Automator As a long time user of OF, this is fantastic. I’m also using the TF of OF4 and was wondering do you have a link to your complete Shortcut + Downloadable script for Agenda for the OmniFocus to New Project in Agenda (Includes: project title, project note, project due date, and project tags) automation ? Thanks

Greetings! Here’s the link to the complete Shortcuts workflow as shown:

https://www.icloud.com/shortcuts/a1974a12ed6349379475531300310cdc

I hope it’s a good starting point for you! Cheers. — Sal

1 Like

Hey guys - this looks like exactly what I’d be looking for to automate project tasks in OF with my notes in Agenda.
However (and I assume this is just me and my utter inability to handle shortcuts) - after installing the above shortcut, I keep getting a message: “Add new note failed because Shortcuts couldn’t convert from Text to Date”.

I’m basically just trying to pull Omni Focus project data and have it show in Agenda note.

Thanks in advance for any help!

Greetings! If you insert a “Show Result” action after the “Get Dictionary from PassedObject” do you see the project data? BTW, OmniFocus 4 has been released! Here’s a link to “What’s new with Omni Automation in OmniFocus 4

Wow thanks for the quick feedback!
Yes, I am indeed using OF 4 now and very much enjoying! I have the plugin installed there, though that function is quite basic and doesnt seem to include all the “extras” from the shortcut, if I’m correct?
Below are images of the messages I’m getting when running the shortcut with “show result” action:


Hmmm. If you click on the noteTitle variable in the Shortcut workflow to summon its connection properties, does it say Dictionary with key “noteTitle”

The issue is with this bit:

“projectDueDate”:‘’"

The OmniFocus project has no due date and so the workflow is failing when trying to add a due date to the Agenda item. Try adding a due date to the project and running again. Let me look at the Omni script code to see if it can be adapted to not having a due date.

It appears the the Agenda shortcut action is not prepared to recieve an empty string as a possible value for the date field.

With a due date, the workflow runs fine:

Yes indeed, this seems to have fixed the issue entirely! I hadn’t added a due date to the project itself - I’ll need to go through and add as each individual task will have its own due date, and project as a whole will have separate. Thanks for the quick help with this one though, I can get started setting this up now :slight_smile: Much appreciated!

1 Like

Thanks so much for this! I’ve just returned to using OmniFocus again now that v4 is released. Being able to connect it to Agenda like this is exactly the sort of thing I had been looking to do, but didn’t know how.

1 Like

@wnknisely You’re most welcome! The new formatting abilities in OmniFocus notes work very well with Agenda so you can style your OmniFocus notes to resemble your work in Agenda. Of course the most useful tool is the bi-directional link between the two apps created by the workflow.

For those interested in learning about the new formatting controls in OmniFocus, there’s a What’s New in Omni Automation for OmniFocus 4 page to provide the details and videos.

Cheers! — SAL

1 Like

Sal,

Just wanted to drop a thank you note for sharing your talents and this automation with the community.

Much appreciated.

Mario.

1 Like

You’re most welcome. Go change the world!