Interoperability: Omni Automation and Alfred

DISCLAIMER: 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.

Alfred is an integrated service for macOS that boosts your efficiency with hotkeys, keywords, text expansion and more. With Alfred, you can search your Mac and the web, and be more productive with custom actions to control your Mac.

With Alfred's workflows, you can extend Alfred and get things done in a customized way. Replace repetitive tasks with workflows, and boost your productivity. And since Alfred workflows support the execution of URLs, Omni Automation Script URLs can easily be turned into actions to be added to Alfred workflows.

The following documentation details the process of turning Omni Automation scripts into an Alfred workflows, available at any time from within the Alfred interface.

(The OmniFocus Collection in the Alfred Gallery)

The OmniFocus Collection Alfred Workflow

The OmniFocus Collection Alfred Workflow (see below) contains four example Alfred actions that are used to demonstrate the following automation scenarios:

In addition, two specialized Alfred actions are included in the Alfred workflow. They are constructed using Apple Events (JXA) but have been included in this collection because of their usefulness.

Each of these example scenarios are detailed in this section of the website.

Before reviewing the examples, šŸ—³ļø DOWNLOAD and install the OmniFocus Collection Alfred Workflow, which will appear like this within the Alfred Preferences application:

The Alfred Workflow

Here is the Alfred workflow and its contents: (click image to view full size)

The OmniFocus Collection opened in the Alfred Preferences application

 1  Alfred Workflows

 2  The OmniFocus Collection Alfred workflow.

 A  Select First Inbox Item • This action will switch the current view in OmniFocus to the Inbox and select the first item.

 B  New Sequential Project • This action will create and select a new sequential project titled using the name entered in Alfred.

 C  Search OmniFocus Projects • This action will use the entered search terms to display a linked list of the matching projects in Alfred.

 D  Tasks Due Today • This action will display a linked list in Alfred of the tasks that are due today.

 E  Display Search Results • This action is called by other actions to display a linked list of items that are the result of a search or filter.

 F  List All Projects • This action displays a linked list of all OmniFocus projects.

 G  List All Tags • This action displays a linked list of all OmniFocus tags.

Scenario 1: Self-Contained Omni Automation Script

This overview begins with an examination of the first automation scenario:

Nearly any Omni Automation script, targeting any of the Omni applications, can be converted into a Script URL, which can be included in an Alfred workflow. When the workflow is triggered, the Script URL will be opened and its encoded Omni Automation script will be sent to the target Omni app to be run.

For purposes of example, the following Omni Automation script targets the OmniFocus application, and will bring the application to the foreground, switch to the Inbox view, and select the first inbox item. This script will be summoned and executed from the Alfred interface.

Using the Omni Automation Script URL Constructor webpage, scripts can be constructed, tested, and transformed into Script URLs. You can even paste your favorite script into the editing pane, tap the ā€œEncode Scriptā€ button and the URL encoding is instantly done for you!

Hereā€™s the example Omni Automation script:

OmniFocus: Select First Inbox Item

(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() document.show() var win = document.windows[0] win.perspective = Perspective.BuiltIn.Inbox tree = win.content tree.select([]) tree.rootNode.children.forEach(node => { node.collapse(true) }) firstTask = tree.rootNode.children[0] if(firstTask){ tree.select([firstTask]) firstTask.expand(true) firstTask.expandNote() firstTask.children.forEach(node => { node.expandNote(true) }) } utterance = createUtterance("Ready!") synthesizer.speakUtterance(utterance) } catch(err){ utterance = createUtterance(err.message) synthesizer.speakUtterance(utterance) //new Alert(err.name, err.message).show() } })();

Here is the example script encoded into a Script URL, ready for use with Alfred:

Encoded Script URL


Creating the Alfred Action

The first example Alfred action is comprised of two steps: (see below)

 A  A Keyword Trigger whose settings indicate the word, characters, or phrase that when entered into the Alfred interface will summon the next step in the action. The default keyword is the letter combination: ib (stands for Inbox) You may have previously changed the keyword during the import of the Alfred workflow.

 B  An Open URL step that will execute the provided URL, or in this case an encoded Omni Automation script URL, using a specified application.

The first Alfred action

Double-click the second step to summon its preferences window: (see below)

The settings for the Open URL step

 1  Copy and paste the Encoded Omni Automation Script URL into the URL field of the dialog.

 2  The local copy of the OmniFocus application should automatically be displayed as the selection in the target application popup menu.

 3  Since there is no data to pass into the Script URL, leave the other Encoding parameters unchecked.

The Alfred action is ready for use.

Executing the Script URL

Once the Alfred bundle is installed, your will be able to summon it from within any application. Open the Alfred input and enter the keyword “ib” (or your customized keyword) in the input field. Arrow-key down to the “Select First Inbox Item” workflow, and press the Return key.

The Alfred interface

The OmniFocus application will switch to the foreground, display the Inbox perspective view, select the first item, and say “Ready!”

First Run Approval

For security, the first time an Omni Automation script URL is run by an external application or link, it must be viewed and approved by the user.

In addition, the user must have previously activated the security setting in the “Security” tab of the “Automation Configuration” dialog (“Automation” menu > “Configureā€¦”) for allowing the execution of external scripts.

Securoity approval for executing external scripts

Once approved, the first time an external script, like the Alfred script, is run, a security dialog like the following will be displayed:


The full code of the script to be executed will be displayed  01  in the security window and must be completely scrolled  02  to enable the “Run Script” button  03  

IMPORTANT: Select the checkbox  04  to indicate that you approve subsequent executions of this script to be done without need for re-approval.

Next Example

In the NEXT EXAMPLE, Alfred is used to launch an Omni Automation script that requires user input within Alfred in order to perform a procedure in OmniFocus.