×

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


omnifocus://localhost/omnijs-run?script=%28async%20%28%29%20%3D%3E%20%7B%0A%09try%20%7B%0A%09%09function%20createUtterance%28textToSpeak%29%7B%0A%09%09%09AlexID%20%3D%20%28%0A%09%09%09%09%28app%2EplatformName%20%3D%3D%3D%20%22macOS%22%29%20%3F%20%0A%09%09%09%09%22com%2Eapple%2Espeech%2Esynthesis%2Evoice%2EAlex%22%20%3A%20%0A%09%09%09%09%22com%2Eapple%2Espeech%2Evoice%2EAlex%22%0A%09%09%09%29%0A%09%09%09voiceObj%20%3D%20Speech%2EVoice%2EwithIdentifier%28AlexID%29%0A%09%09%09voiceRate%20%3D%200%2E4%0A%09%09%09utterance%20%3D%20new%20Speech%2EUtterance%28textToSpeak%29%0A%09%09%09utterance%2Evoice%20%3D%20voiceObj%0A%09%09%09utterance%2Erate%20%3D%20voiceRate%0A%09%09%09return%20utterance%0A%09%09%7D%0A%09%09var%20synthesizer%20%3D%20new%20Speech%2ESynthesizer%28%29%0A%0A%09%09document%2Eshow%28%29%0A%09%09var%20win%20%3D%20document%2Ewindows%5B0%5D%0A%09%09win%2Eperspective%20%3D%20Perspective%2EBuiltIn%2EInbox%0A%09%09tree%20%3D%20win%2Econtent%0A%09%09tree%2Eselect%28%5B%5D%29%0A%09%09tree%2ErootNode%2Echildren%2EforEach%28node%20%3D%3E%20%7B%0A%09%09%09node%2Ecollapse%28true%29%0A%09%09%7D%29%0A%09%09firstTask%20%3D%20tree%2ErootNode%2Echildren%5B0%5D%0A%09%09if%28firstTask%29%7B%0A%09%09%09tree%2Eselect%28%5BfirstTask%5D%29%0A%09%09%09firstTask%2Eexpand%28true%29%0A%09%09%09firstTask%2EexpandNote%28%29%0A%09%09%09firstTask%2Echildren%2EforEach%28node%20%3D%3E%20%7B%0A%09%09%09%09node%2EexpandNote%28true%29%0A%09%09%09%7D%29%0A%09%09%7D%0A%09%0A%09%09utterance%20%3D%20createUtterance%28%22Ready%21%22%29%0A%09%09synthesizer%2EspeakUtterance%28utterance%29%0A%09%7D%0A%09catch%28err%29%7B%0A%09%09utterance%20%3D%20createUtterance%28err%2Emessage%29%0A%09%09synthesizer%2EspeakUtterance%28utterance%29%0A%09%09%2F%2Fnew%20Alert%28err%2Ename%2C%20err%2Emessage%29%2Eshow%28%29%0A%09%7D%0A%7D%29%28%29%3B

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:

Alfred-first-run-script-secuirty-dialog

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.