VCOF0111
OmniFocus: Link Project Pair
This command appends links to each of the selected pair of projects to each other’s note.
Scope and Syntax
Language: English (United States 🇺🇸 · Great Britain 🇬🇧 · Australia 🇦🇺 · Canada 🇨🇦) • Scope: OmniFocus
Command phrase variations (words in [brackets] are optional):
- “Link Project Pair”
Requirements
- Application: OmniFocus 4, OmniFocus: 3.13 (macOS)
- System: macOS 12, iOS 15, iPadOS 15
Video: Link Project Pair |
This command appends links to each of the selected pair of projects to each other’s note. |
|
Downloads
- ⇩ COMMANDS-FILE OmniFocus 4.0 (macOS)
- ⇩ COMMANDS-FILE OmniFocus 3.13 (macOS)
- ⇩ SHORTCUT-LINK (“Link Project Pair”)
Script Code
Here is the script code:
Link Project Pair
(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()
sel = document.windows[0].selection.projects
if(sel.length !== 2){
throw {
name: "Selection Issue",
message: "Please select two project to be linked."
}
} else {
projA = sel[0]
projB = sel[1]
projATitle = projA.name
projBTitle = projB.name
projALink = `omnifocus:///task/${projA.id.primaryKey}`
projBLink = `omnifocus:///task/${projB.id.primaryKey}`
projAInsert = `${projATitle} <${projALink}>`
projBInsert = `${projBTitle} <${projBLink}>`
if(projA.note.length === 0){
projA.note = projBInsert
} else {
projA.note = projA.note + "\n" + projBInsert
}
if(projB.note.length === 0){
projB.note = projAInsert
} else {
projB.note = projB.note + "\n" + projAInsert
}
tree = document.windows[0].content
projANode = tree.nodeForObject(projA)
projANode.expandNote(true)
projBNode = tree.nodeForObject(projB)
projBNode.expandNote(true)
utterance = createUtterance("Projects linked!")
synthesizer.speakUtterance(utterance)
}
}
catch(err){
utterance = createUtterance(err.message)
synthesizer.speakUtterance(utterance)
//new Alert(err.name, err.message).show()
}
})();
Link Project Pair
(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()
sel = document.windows[0].selection
items = sel.databaseObjects.filter(
item => (item instanceof Project || item instanceof Task)
)
if(items.length === 1){
var item = sel.databaseObjects[0]
// create the callback-url using data from selected project or task
encodedTitle = encodeURIComponent(item.name)
encodedNote = encodeURIComponent(item.note)
itemLink = `[OmniFocus](omnifocus:///task/${item.id.primaryKey})`
encodedLink = encodeURIComponent(itemLink)
urlStr = "agenda://x-callback-url/create-note"
urlStr += `?title=${encodedTitle}`
urlStr += `&text=${encodedLink}%0A`
urlStr += `${encodedNote}`
// add due date if used
if(item.dueDate){
fmtr = Formatter.Date.withFormat('yyyy-MM-dd')
dateStr = fmtr.stringFromDate(item.dueDate)
urlStr += `&date=${dateStr}`
}
// convert url string to URL object
callingURL = URL.fromString(urlStr)
// call the URL and use the response
callingURL.call(function(noteID){
// use the returned note identifier to create link
linkStr = `agenda://x-callback-url/open-note`
linkStr += `?identifier=${noteID}`
console.log(linkStr)
linkURL = URL.fromString(linkStr)
// prepend the link object to the item note
noteObj = item.noteText
linkURL = URL.fromString(linkStr)
linkObj = new Text("(Agenda Link)", noteObj.style)
newLineObj = new Text("\n", noteObj.style)
style = linkObj.styleForRange(linkObj.range)
style.set(Style.Attribute.Link, linkURL)
noteObj.insert(noteObj.start, linkObj)
noteObj.insert(linkObj.range.end, newLineObj)
// reveal the note
node = document.windows[0].content.selectedNodes[0]
node.expandNote(false)
// completion announcement
utterance = createUtterance("Done!")
synthesizer.speakUtterance(utterance)
}, function(err){
throw {
name: "Script Error",
message: err.errorMessage
}
})
} else {
throw {
name: "Selection Issue",
message: "Please select a single project or task."
}
}
}
catch(err){
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.