VCOO0024
OmniOutliner: Convert Outline to Project
This command uses the data from the outline to construct a new project in OmniFocus.
The item hierarchy, as well as all item notes, are transfered to the project.
Scope and Syntax
Language: English (United States 🇺🇸 · Great Britain 🇬🇧 · Australia 🇦🇺 · Canada 🇨🇦)
Scope: OmniOutliner
Command phrase variations (words in [brackets] are optional):
- “Convert Outline to Project”
Requirements
- Application: OmniOutliner: 5.10 (macOS), OmniOutliner 3.9.1 (iOS/iPadOS), OmniFocus 3.13 (macOS/iOS,iPadOS)
- System: macOS 12, iOS 15, iPadOS 15
Video: Convert Outline to Project |
This command uses the data from the outline to construct a new project in OmniFocus. |
|
Script Code
Here is the script code for the commands.
The first version of the script automatically creates a new project using the default project settings indicated in the script:
Downloads
- ⇩ COMMANDS-FILE (OmniOutliner 5) (macOS)
- ⇩ SHORTCUT-LINK (“Convert Outline to Project”) (iOS/iPadOS)
- ⇩ SHORTCUT-LINK (“Split [OmniOutliner] with OmniFocus”) (iOS/iPadOS)
Convert Outline to Project
(async () => {
try {
function createUtterance(textToSpeak){
AlexID = (
(app.platformName === "macOS") ?
"com.apple.speech.synthesis.voice.Alex" :
"com.apple.speech.voice.Alex"
)
voiceObj = Speech.Voice.withIdentifier(AlexID)
voiceRate = 0.4
utterance = new Speech.Utterance(textToSpeak)
utterance.voice = voiceObj
utterance.rate = voiceRate
return utterance
}
var synthesizer = new Speech.Synthesizer()
try {document.name} catch(err){
throw {name:"Missing Resource", message:"No outline document is open."}
}
documentName = document.name.replace(/\.[^/.]+$/, "")
console.log("DOCUMENT NAME:", documentName)
// GET DATA AS JSON RECORD ARRAY
itemData = rootItem.descendants.map(item => {
itemObj = new Object()
itemObj.level = item.level
itemObj.topic = item.topic
itemObj.note = item.note
return itemObj
})
console.log("ITEM DATA:", JSON.stringify(itemData))
// DEFAULT PROJECT SETTINGS
projectTitle = documentName
projectTypeIndex = 0 // Parallel = 0, Sequential = 1, Single Actions = 2
completedByActions = false
// THE OPTIONAL ARGUMENT MAY BE: string, number, date, array, or object
var targetFunctionArgument = {
"items": itemData,
"title": projectTitle,
"projectTypeIndex": projectTypeIndex,
"completedByActions": completedByActions
}
var targetAppName = "omnifocus"
// THE FUNCTION TO BE EXECUTED ON THE TARGET APP
function targetAppFunction(targetFunctionArgument){
try {
dataItems = targetFunctionArgument["items"]
projectTitle = targetFunctionArgument["title"]
projectTypeIndex = targetFunctionArgument["projectTypeIndex"]
completedByActions = targetFunctionArgument["completedByActions"]
var project = new Project(projectTitle)
project.status = Project.Status.Active
if (projectTypeIndex === 1){
project.sequential = true
} else if (projectTypeIndex === 2){
project.containsSingletonActions = true
}
project.completedByChildren = completedByActions
// link-back to project
projectID = project.id.primaryKey
var linkURL = "omnifocus:///task/" + projectID
console.log("PROJECT LINK:", linkURL)
var previousItem = null
var previousLevel = null
var insertionLocation = null
dataItems.forEach((dataItem, index, dataArray) => {
itemLevel = dataItem.level
itemTopic = dataItem.topic
itemNote = dataItem.note
if (itemLevel > 1){ // child or sibling of previous item
if(itemLevel === previousLevel){ // sibling
insertionLocation = previousItem.parent.ending
} else if (itemLevel > previousLevel){ // child
insertionLocation = previousItem.ending
} else if (itemLevel < previousLevel){ // calculate previous parent
var parentItem = project.task
for(var i = 0; i < (itemLevel -1); i++){
parentItem = parentItem.tasks.pop()
}
insertionLocation = parentItem.ending
}
} else {
insertionLocation = project.ending
}
task = new Task(itemTopic, insertionLocation)
task.note = itemNote
previousItem = task
previousLevel = itemLevel
})
document.windows[0].focus = [project]
// return link to project to calling script
return linkURL
}
catch(err){
console.error(err.name, err.message)
throw {
name: err.name,
message: err.message
}
}
}
// CREATE SCRIPT URL WITH FUNCTION AND PASSED DATA
scriptURL = URL.tellFunction(
targetAppName,
targetAppFunction,
targetFunctionArgument
)
// CALL THE SCRIPT URL, PROCESS RESULTS OR ERROR
// WRAP IN PROMISE TO GIVE PASSED SCRIPT TIME TO COMPLETE
var result = new Promise((resolve, reject) => {
scriptURL.call(reply => {
// PROCESS RESULTS OF SCRIPT
if(reply){
console.log("CALL RESULT:", reply)
// open returned link to show new project
URL.fromString(reply).open()
}
utterance = createUtterance("Done!")
synthesizer.speakUtterance(utterance)
resolve("done")
}, error => {
// PROCESS SCRIPT ERROR
console.error("CALL ERROR:", error.errorMessage)
throw error
reject(error.errorMessage)
})
})
await result
}
catch(err){
if(!err.causedByUserCancelling){
utterance = createUtterance(err.message)
synthesizer.speakUtterance(utterance)
//new Alert(err.name, err.message).show()
}
}
})();
The second version of the script prompts the user to enter and choose the settings for the created project:
Downloads
- ⇩ COMMANDS-FILE (OmniOutliner 5) (macOS)
- ⇩ SHORTCUT-LINK (“Convert Outline to Project”) (iOS/iPadOS)
Convert Outline to Project
(async () => {
try {
function createUtterance(textToSpeak){
AlexID = (
(app.platformName === "macOS") ?
"com.apple.speech.synthesis.voice.Alex" :
"com.apple.speech.voice.Alex"
)
voiceObj = Speech.Voice.withIdentifier(AlexID)
voiceRate = 0.4
utterance = new Speech.Utterance(textToSpeak)
utterance.voice = voiceObj
utterance.rate = voiceRate
return utterance
}
var synthesizer = new Speech.Synthesizer()
try {document.name} catch(err){
throw {name:"Missing Resource", message:"No outline document is open."}
}
documentName = document.name.replace(/\.[^/.]+$/, "")
console.log("DOCUMENT NAME:", documentName)
// GET DATA AS JSON RECORD ARRAY
itemData = rootItem.descendants.map(item => {
itemObj = new Object()
itemObj.level = item.level
itemObj.topic = item.topic
itemObj.note = item.note
return itemObj
})
console.log("ITEM DATA:", JSON.stringify(itemData))
// CONSTRUCT AND DISPLAY FORM
textInputField = new Form.Field.String(
"projectTitle",
"Project Title",
documentName
)
menuItems = ["Parallel", "Sequential", "Single Actions"]
menuIndexes = [0,1,2]
menuElement = new Form.Field.Option(
"projectTypeIndex",
"Project Type",
menuIndexes,
menuItems,
0
)
completedByChildrenCheckbox = new Form.Field.Checkbox(
"completedByActions",
"Complete with last action",
null
)
inputForm = new Form()
inputForm.addField(textInputField)
inputForm.addField(menuElement)
inputForm.addField(completedByChildrenCheckbox)
inputForm.validate = function(formObject){
projectTitle = formObject.values['projectTitle']
return ((!projectTitle)?false:true)
}
formPrompt = "Title and settings for new project:"
buttonTitle = "Continue"
utterance = createUtterance(formPrompt)
synthesizer.speakUtterance(utterance)
formObject = await inputForm.show(formPrompt, buttonTitle)
projectTitle = formObject.values['projectTitle']
projectTypeIndex = formObject.values['projectTypeIndex']
completedByActions = formObject.values['completedByActions']
// THE OPTIONAL ARGUMENT MAY BE: string, number, date, array, or object
var targetFunctionArgument = {
"items": itemData,
"title": projectTitle,
"projectTypeIndex": projectTypeIndex,
"completedByActions": completedByActions
}
var targetAppName = "omnifocus"
// THE FUNCTION TO BE EXECUTED ON THE TARGET APP
function targetAppFunction(targetFunctionArgument){
try {
dataItems = targetFunctionArgument["items"]
projectTitle = targetFunctionArgument["title"]
projectTypeIndex = targetFunctionArgument["projectTypeIndex"]
completedByActions = targetFunctionArgument["completedByActions"]
var project = new Project(projectTitle)
project.status = Project.Status.Active
if (projectTypeIndex === 1){
project.sequential = true
} else if (projectTypeIndex === 2){
project.containsSingletonActions = true
}
project.completedByChildren = completedByActions
// link-back to project
projectID = project.id.primaryKey
var linkURL = "omnifocus:///task/" + projectID
console.log("PROJECT LINK:", linkURL)
var previousItem = null
var previousLevel = null
var insertionLocation = null
dataItems.forEach((dataItem, index, dataArray) => {
itemLevel = dataItem.level
itemTopic = dataItem.topic
itemNote = dataItem.note
if (itemLevel > 1){ // child or sibling of previous item
if(itemLevel === previousLevel){ // sibling
insertionLocation = previousItem.parent.ending
} else if (itemLevel > previousLevel){ // child
insertionLocation = previousItem.ending
} else if (itemLevel < previousLevel){ // calculate previous parent
var parentItem = project.task
for(var i = 0; i < (itemLevel -1); i++){
parentItem = parentItem.tasks.pop()
}
insertionLocation = parentItem.ending
}
} else {
insertionLocation = project.ending
}
task = new Task(itemTopic, insertionLocation)
task.note = itemNote
previousItem = task
previousLevel = itemLevel
})
document.windows[0].focus = [project]
// return link to project to calling script
return linkURL
}
catch(err){
console.error(err.name, err.message)
throw {
name: err.name,
message: err.message
}
}
}
// CREATE SCRIPT URL WITH FUNCTION AND PASSED DATA
scriptURL = URL.tellFunction(
targetAppName,
targetAppFunction,
targetFunctionArgument
)
// CALL THE SCRIPT URL, PROCESS RESULTS OR ERROR
// WRAP IN PROMISE TO GIVE PASSED SCRIPT TIME TO COMPLETE
var result = new Promise((resolve, reject) => {
scriptURL.call(reply => {
// PROCESS RESULTS OF SCRIPT
if(reply){
console.log("CALL RESULT:", reply)
// open returned link to show new project
URL.fromString(reply).open()
}
utterance = createUtterance("Done!")
synthesizer.speakUtterance(utterance)
resolve("done")
}, error => {
// PROCESS SCRIPT ERROR
console.error("CALL ERROR:", error.errorMessage)
throw error
reject(error.errorMessage)
})
})
await result
}
catch(err){
if(!err.causedByUserCancelling){
utterance = createUtterance(err.message)
synthesizer.speakUtterance(utterance)
//new Alert(err.name, err.message).show()
}
}
})();
LEGAL
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Mention of third-party websites and products is for informational purposes only and constitutes neither an endorsement nor a recommendation. OMNI-AUTOMATION.COM assumes no responsibility with regard to the selection, performance or use of information or products found at third-party websites. OMNI-AUTOMATION.COM provides this only as a convenience to our users. OMNI-AUTOMATION.COM has not tested the information found on these sites and makes no representations regarding its accuracy or reliability. There are risks inherent in the use of any information or products found on the Internet, and OMNI-AUTOMATION.COM assumes no responsibility in this regard. Please understand that a third-party site is independent from OMNI-AUTOMATION.COM and that OMNI-AUTOMATION.COM has no control over the content on that website. Please contact the vendor for additional information.