Craft eXtension: Log Selection Data to OmniFocus Console
A very useful tool for eXtension developers, this Craft extension will log the data of the Craft selection to the OmniFocus console as formatted JSON.
The Craft eXtension File
Download the eXtension file and install by clicking the plus (+) button in the eXtensions pane in the current document window.
JavaScript Script in HTML Page
This script, placed inside the button handler, extracts the current Craft selection data and constructs and Omni Automation script URL to send it to OmniFocus to display in the Console.
Related Links:
Script URL for Sending Content Data to OmniFocus
btn.addEventListener("click", async () => {
try {
// GET THE CURRENT SELECTION
result = await craft.editorApi.getSelection()
if (result.status !== "success") {
throw new Error(result.message)
} else {
var selectionData = result.data
}
// 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}`
}
});