“Omni Automation Script” Action Interface
The “Omni Automation Script” action for Shortcuts is designed to enable the execution of Omni Automation scripts within a Shortcuts’ workflow (shortcut).
This action presents a simple interface with options for accepting data input, identified related files, and the code of the Omni Automation script placed within its interface.
The action interface is as shown (except for the app icon), regardless of the hosting Omni application: OmniFocus, OmniGraffle, OmniPlan, and OmniOutliner.
Script Template: Asynchronous Wrapper with Error Handler
Use this script template with the “Omni Automation Script” action:
- If your script incorporates the display of an action form
- If your script may need to display an error message to the user
Asynchronous Wrapper with Error Handler
(async () => {
try {
// SCRIPT STATEMENTS GO HERE
}
catch(err){
if(!err.causedByUserCancelling){
await new Alert(err.name, err.message).show()
}
throw `${err.name}\n${err.message}`
}
})();
NOTE: this script will stop its parent shortcut workflow after the error message has been displayed in the host Omni application.
Example Script with No Input
Scripts used with the “Omni Automation Script” action for Shortcuts can be simple or complex, comprising a few lines or many lines of code. Scripts may even include Omni Automation Forms in order to present interfaces to the user to collect data or indicate selections.
The following is an example Omni Automation script that, while requiring no input, presents a simple menu form to the user, and returns the value of the chosen option back to the parent Shortcut (workflow). This example script works with any of the Omni applications.
Return Title of Chosen Menu Item
(async () => {
try {
weekDays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
weekdaysMenu = new Form.Field.Option(
"weekday",
null,
weekDays,
weekDays,
"Sunday"
)
inputForm = new Form()
inputForm.addField(weekdaysMenu)
formPrompt = "Choose a day:"
buttonTitle = "Continue"
formObject = await inputForm.show(formPrompt, buttonTitle)
weekday = formObject.values["weekday"]
return weekday
}
catch(err){
if(!err.causedByUserCancelling){
await new Alert(err.name, err.message).show()
}
throw `${err.name}\n${err.message}`
}
})()
The Shortcuts Workflow (shortcut) [DOWNLOAD]
Next…
The next section of this documentation demonstrates how various data types may be passed into the “Omni Automation Script” action via the action’s Input Socket.