Omni Automation and Craft

Greetings!

There’s a new section of the Omni Automation website dedicated to documenting examples of integration between applications from The Omni Group and Craft. The provided examples use Omni Automation scripts, plug-ins, and shortcuts, with the Craft API to share data between Craft and the Omni suite of applications: OmniFocus, OmniGraffle, OmniOutliner, and OmniPlan

Your comments, insights, and suggestions shared here in this forum, are most welcome.

https://omni-automation.com/craft/index.html

3 Likes

When creating automations involving Craft content, it is often useful to be able to access the metadata of the selected content, such as block and space IDs, and hidden URLs. The Craft eXtension linked here will display the data for the current Craft selection in the OmniFocus console as formatted JSON.

Very useful!

https://omni-automation.com/craft/omnifocus-log-craft-data.html

Omni Automation Script URLs are used to externally query and control Omni applications.

In the Craft eXtension code for the logging data example, the Omni Automation script URL is constructed to pass both the function to be executed by the targeted Omni application, as well as the data to be processed. By passing the data separately from the function, the script can be user-approved to execute without further prompting in the future.

Here is the embedded script code from the eXtension index.html file, triggered when the user clicks the button with an assigned event listener:

<script>
	const button = document.getElementById("run-script-btn");
	button.addEventListener("click", async () => {
		try {
			// GET THE SELECTION
			result = await craft.editorApi.getSelection()
			if (result.status !== "success") {
				throw new Error(result.message)
			} else {
				var selectionData = result.data
			}
	
			// OMNI AUTOMATION SCRIPT URL DOCUMENTATION
			// https://omni-automation.com/script-url/index.html

			// FUNCTION TO BE EXECUTED BY OMNIFOCUS
			function logToOmniFocusConsole(passedData){
				console.log(JSON.stringify(passedData, null, 2))
			}

			// CREATE FUNCTION AND CONTENT STRINGS
			contentString = JSON.stringify(selectionData)
			encodedContent = encodeURIComponent(contentString)
			functionString = logToOmniFocusConsole.toString()
			encodedFunction = encodeURIComponent(functionString)

			// CREATE SCRIPT URL
			url = 'omnifocus://localhost/omnijs-run?script=' +
			'%28' + encodedFunction + '%29' +
			'%28' + 'argument' + '%29' +
			'&arg=' + encodedContent

			// EXECUTE THE URL
			await craft.editorApi.openURL(url)
		}
		catch(err){
			throw `${err.name}\n${err.message}`
		}
	});
</script>

This is a great resource!

NEW! Craft eXtension Tutorial: Recreating Structured Content in OmniFocus

Shows step-by-step how to create a custom Craft eXtension that enables the recreation of structured Craft content in OmniFocus. In this example, a new OmniFocus project is created using the data from a selected project in Craft. Detailed documentation.

Documentation

1 Like