Shortcuts Examples for OmniFocus
This page contains example Shortcuts workflows and templates demonstrating the use of Omni Automation with the Shortcuts application.
- Dictate Note for Selected Task or Project (shortcut)
- Get Selected Project (template)
- Get Selected Task (template)
- Export Data of Selected Projects as TaskPaper (template)
- Returns a Markdown link to the selected item (template)
- Append Map Link for Nearby Business to Task/Project Note (shortcut)
- New Task for Selected Mail Message (shortcut)
OmniFocus • Dictate Note for Selected Task or Project
A shortcut that either replaces or appends the contents of the note of the selecte OmniFocus task or project with the user’s dictated text. (DOWNLOAD)
This shortcut incorporates two instances of the “Omni Automation Script” action. The script for the first action is provided below:
Return Primary Key (ID) of Selected Task or Project
try {
var sel = document.windows[0].selection
var selCount = sel.tasks.length + sel.projects.length
if(selCount === 1){
if (sel.tasks.length === 1){
var selectedItem = sel.tasks[0]
} else {
var selectedItem = sel.projects[0]
}
} else {
throw {
name: "Selection Issue",
message: "Please select a single project or task."
}
}
selectedItem.id.primaryKey
}
catch(err){
var alertPromise = new Alert(err.name, err.message).show()
alertPromise.then(buttonIndex => {throw new Error(-128)})
}
1 “Open App” action • This action makes OmniFocus the active application.
2 “Omni Automation Script” action • This action contains an Omni Automation script targeting the OmniFocus application.
3 Omni Automation script • This script is designed to check for a single selected OmniFocus task or project. If the selection requirements are not met, and error message is displayed and the shortcut is halted.
4 Return Object’s ID • Passing the unique identifier of the selected object, which is the value of its primaryKey property. (related documentation)
5 “Dictate Text” action • Shortcuts’ built-in action for enabling the user to pass dictated text in a shortcut.

6 “Dictionary” action • Shortcuts’ built-in action for creating a dictionary of keys and their corresponding values. This dictionary will contain the selected OmniFocus object’s unique identifier (primaryKey), as well as the note text dictated by the user.
7 Data Input Socket • The created dictionary is placed in the Data Input Socket of a second “Omni Automation Script” action for OmniFocus.
8 Omni Automation script • This asynchronous function presents a options menu to the user for them to select the editing method used with the selected object’s note: Replace or Append to the existing note.
X Retrieve passed data • The argument.input parameter is used to retrieve the passed identifier and the dictated text, which are then used to edit the note of the selected object accorgingly.
(below) The script of the second instance of the “Omni Automation Script” action prompts the user to choose the method for editing the existing note, and then retrieves the passed OmniFocus object ID and the dictated text in order to locate and edit the note of the selected OmniFocus object. Note that the unique identifier (primaryKey) of the selected object is returned by the function, thereby passing it back to the parent shortcut workflow.
Change the Note Content
(async () => {
try {
var editMethodMenu = new Form.Field.Option(
"editMethod",
null,
["Replace", "Append"],
["Replace", "Append"],
"Replace"
)
var inputForm = new Form()
inputForm.addField(editMethodMenu)
var formPrompt = "Use dictation to:"
var formObject = await inputForm.show(formPrompt, "Continue")
var editMethod = formObject.values["editMethod"]
var passedID = argument.input.objectID
var dictatedText = argument.input.dictation
var selectedItem = Task.byIdentifier(passedID)
if(!selectedItem){selectedItem = Project.byIdentifier(passedID)}
if(editMethod === "Replace"){
selectedItem.note = dictatedText
} else {
selectedItem.note = selectedItem.note + "\n" + dictatedText
}
return selectedItem.id.primaryKey
}
catch(err){
if(!err.message.includes("cancelled")){
await new Alert(err.name, err.message).show()
}
throw `${err.name}\n${err.message}`
}
})();
OmniFocus • Get Selected Project
The actions of the following shortcut can be used to return an object reference to the currently selected project. These actions can be copied and pasted into your shortcut. (DOWNLOAD)

Get Selected Project
try {
var sel = selection.projects
if(sel.length === 1){
var selectedItem = sel[0]
} else {
throw {
name: "Selection Issue",
message: "Please select a single project."
}
}
var itemProperties = new Object()
itemProperties["primaryKey"] = selectedItem.id.primaryKey
itemProperties["type"] = "project"
itemProperties["version"] = 1.0
JSON.stringify(itemProperties)
}
catch(err){
var alertPromise = new Alert(err.name, err.message).show()
alertPromise.then(result => {throw new Error(-128)})
}
OmniFocus • Get Selected Task
The actions of the following shortcut can be used to return an object reference to the currently selected task. These actions can be copied and pasted into your shortcut. (DOWNLOAD)

Get Selected Task
try {
var sel = selection.task
if(sel.length === 1){
var selectedItem = sel[0]
} else {
throw {
name: "Selection Issue",
message: "Please select a single task."
}
}
var itemProperties = new Object()
itemProperties["primaryKey"] = selectedItem.id.primaryKey
itemProperties["type"] = "task"
itemProperties["version"] = 1.0
JSON.stringify(itemProperties)
}
catch(err){
var alertPromise = new Alert(err.name, err.message).show()
alertPromise.then(result => {throw new Error(-128)})
}
OmniFocus • Export Selected Projects as TaskPaper
The actions of the following shortcut can be used to return the currently selected projects as TaskPaper data (text). These actions can be copied and pasted into your shortcut. (DOWNLOAD)
This template works with Apple Notes, Apple Mail, Drafts, Bear, Craft, and other 3rd-party applications with integrated Shortcuts support that accept text as input.
1 “Open App” action • Make OmniFocus the active application.
2 “Omni Automation Script” action • An asynchronous JavaScript function that returns the data of the selected projects in TaskPaper format.

3 FileWrapper • Create a FileWrapper instance containing the data of the selected projects in TaskPaper format.
4 Return TaskPaper Text • Return the text contents of the created FileWrapper.
Export Selected Projects as TaskPaper Data (text)
(async () => {
if(!selection.projects.length > 0){
throw {
name: "Selection Issue",
message: "Please select one or more projects."
}
}
var fileTypeID = "com.omnigroup.omnifocus2.export-filetype.plain-text"
var baseName = "TaskPaper-Export"
var wrapper = await document.makeFileWrapper(baseName, fileTypeID)
var wrapperContents = wrapper.contents.toString()
return wrapperContents
})().catch(err => {
var alertPromise = new Alert(err.name, err.message).show()
alertPromise.then(buttonIndex => {throw new Error(-128)})
})
OmniFocus • Markdown Link to Selected Item
The actions of the following shortcut can be used to return a link in Markdown format to the currently selected project, task, tag, or folder. These actions can be copied and pasted into your shortcut. (DOWNLOAD)
This template works with Apple Notes, Apple Mail, Drafts, Bear, Craft, and other 3rd-party applications with integrated Shortcuts support that accept text as input.

Markdown Link of Selected Item
try {
var sel = selection.databaseObjects
if(sel.length === 1){
var selectedItem = sel[0]
if (selectedItem instanceof Folder){
var objType = "folder"
} else if (selectedItem instanceof Tag){
var objType = "tag"
} else {
var objType = "task"
}
} else {
throw {
name: "Selection Issue",
message: "Please select a single task, project, folder, or tag."
}
}
var ID = selectedItem.id.primaryKey
var urlStr = `omnifocus:///${objType}/${ID}`
var markdownLink = `[${selectedItem.name}](${urlStr})`
markdownLink
}
catch(err){
var alertPromise = new Alert(err.name, err.message).show()
alertPromise.then(result => {throw new Error(-128)})
}
OmniFocus • Append Map Link for Nearby Business to Task/Project Note
This Shortcuts example will prompt the user to search for a nearby business and then append a Maps link for the chosen business, to the note of the selected project or task. (DOWNLOAD)
1 “Open App” action • Make OmniFocus the active application.
2 “Omni Automation Script” action • This action will execute its Omni Automation script.
3 Script Code • A script that returns the value of the primaryKey property of the single selected task or project 4 If a single project or task is not selected, an error message will be displayed to the user, and the workflow halted.

5 Map Search • A map search input dialog will be displayed, passing the matched items to the following action. NOTE: by default this action is set to search for local businesses within a 2-mile radius of your current location. Adjust these settings to match your preferred values.
6 List of Matches • Presents a list of matching businesses, the chosen list item is passed to the following action.
7 Map Link (URL) • An Apple Maps link to the selected business is generated.
8 Data Dictionary • A data dictionary (record) is created containing the passed values from the previous actions: the ID of selected task/project; the Maps URL of the chosen business.
9 Data Input Socket • The data dictionary is placed in the Data Input Socket of the “Omni Automation Script” action.
10 Omni Automation script • This script uses the argument.input parameter to extract the data passed within the data dictionary, and then uses that data to located the selected OmniFocus task/project and append the Maps link to its note.
Here are the Omni Automation scripts used in this Shortcuts workflow:
Return Identifier of Selected Task or Project
(async () => {
try {
var sel = document.windows[0].selection
var selCount = sel.tasks.length + sel.projects.length
if(selCount === 1){
if (sel.tasks.length === 1){
var selectedItem = sel.tasks[0]
} else {
var selectedItem = sel.projects[0]
}
return selectedItem.id.primaryKey
} else {
throw {
name: "Selection Issue",
message: "Please select a single project or task."
}
}
}
catch(err){
if(!err.message.includes("cancelled")){
await new Alert(err.name, err.message).show()
}
throw `${err.name}\n${err.message}`
}
})();
Process Passed Data Dictionary
var url = argument.input.mapsURL
var ID = argument.input.objectID
var item = Task.byIdentifier(ID)
if (!item){item = Project.byIdentifier(ID)}
if(item.note.length === 0){
item.appendStringToNote(url)
} else {
item.appendStringToNote( "\n" + url)
}
OmniFocus • New Task for Selected Mail Message
This “macOS only” shortcut uses an AppleScript script to extract information about the currently selected Mail message, and pass it to the shortcut as a Dictionary.
The passed data is then used to create a new task in OmniFocus with the subject of the selected Mail message becoming the title of the created task. In addition, a link to the selected Mail message is placed in the note of the newly created task. (DOWNLOAD)
1 “Run AppleScript” action • This action for macOS Shortcuts app enables the execution of the provided AppleScript script.
2 AppleScript Script • This script locates the selected Mail message and creates and returns a record (dictionary) of two message properties: subject and the message’s message id as a URL (link).
3 Dictionary • This action converts the passed AppleScript record into a dictionary usable by Shortcuts.
4 “Open App” action • Makes OmniFocus the active application.

5 “Add Item” action • This action is used to create a new OmniFocus task in the inbox. The Mail message subject is passed as the title of the new task.
6 Message Link • The link to the Mail message becomes the value of the note of the new task.
7 “Show Item” action • Selects and displays the created task in the OmniFocus window.
AppleScript: Pass Dictionary of Selected Message
tell application "Mail"
set msgs to selected messages of front message viewer
if (count of msgs) is 1 then
set selMsg to item 1 of msgs
set msgID to message id of selMsg
set msgURL to "message:%3C" & msgID & "%3E"
set msgTitle to subject of selMsg
return "{\"msgURL\":\"" & msgURL & "\",\"msgTitle\":\"" & msgTitle & "\"}"
else
activate
display alert "Selection" message "Please select a single Mail message." buttons {"OK"}
error number -128
end if
end tell