26 julio, 2024

Development of workflows in Alfred App by @sarofr | Bootcamps

Do you know what workflow development in Alfred App is about? Alfred, for those who do not yet know it (as surprising as this may be), is an application focused on improving productivity. It allows you to launch applications, search and open files on your Mac, and even search the Internet. It is, roughly speaking, a supervitamined and mineralized Spotlight.

This is an application free to which, if you wish, you can increase its possibilities by purchasing the PowerPack. Version 1 is available in the App Storebut due to the restrictions that Apple imposes on its download store, the version 2 is only available from its own website.

Without a doubt, the possibility of using workflows is worth, in itself, the 17 pounds (about €21.5) that the individual license costs, although there are other licenses.

Although, after the presentation of OSX Yosemite at the last WWDC, many predicted the end of Alfred in favor of the “new” Spotlight, it does not seem that Andrew and Vero Pepperell (the team behind Alfred) were of any concern (at less apparently) if we trust the post they published on their blog and which I translate below:

Remember that the main purpose of Spotlight is to search your files and a small number of web sources. While the main goal of Alfred is to make you more productive on your Mac with exceptional and powerful functionalities such as clipboard history, system commands, iTunes Mini player, 1Password bookmarks, Terminal integration, custom user-created workflows and customizable and much, much more. These features allow you to mold Alfred to your needs, and this does not change whether you use the free version of Alfred or the PowerPack. And I have to say that, personally, I quite agree with the arguments they put forward.

Without disparaging the new Spotlight, I think it has a long way to go to eclipse Alfred. But we already know how Apple spends it…

It is on these workflows that we are going to focus the content of this post and where we will see that, with little effort, we can achieve quite interesting things.

As we have already said, in order to create and/or import custom workflows it is necessary to have previously purchased the PowerPack.

Before starting to develop our own workflow, it is worth spending 5 minutes taking a look at ****://www.packal.org/ and ****://www.alfredworkflow.com/ so as not to reinvent the wheel. If we have not found anything that serves (or resembles) what we need, or we simply want to feel the satisfaction that DIY produces, then what we will have to do is create our own workflow.

For simple processes Alfred offers a series of templates that can be used as a starting point although, if we are going for the hard stuff, we can also choose the “blank workflow”. Once a template or blank workflow has been chosen, we have four objects that we can add:

Triggers

They are the starting point of any workflow, they are responsible for capturing the event that will launch its execution. We have five types:

hotkey

They allow actions to be executed without having to show Alfred, or show Alfred with predefined information. Let’s see with a very simple example: we want the Agbo website to open in a specific browser when we press a certain key combination (in this case we will tell it to be Chrome).

The first thing we will do is add an object Hotkey. We will define the key combination that we will use and we will tell it to be Pass through to workflow so that this way it will be launched without needing to show Alfred and, in this case, Argument to None:

Once defined the hotkey we add a action (we will see it in the next post but we need it to test now) type Open URL. We will define the URL that we want to be displayed and in which Browser:

Finally, to link the two objects, we place the mouse pointer near the right side of the hotkey and when the «bulge» appears, click and drag to the action:

We can verify that if we click ^???C The defined URL opens in Chrome. To end the hotkeys We are going to make a small change so that Alfred is now displayed. It will be passed a “define” prefix (which invokes an internal workflow) and the text that we have selected at the moment:

We check that if we select a text and press ^???C Alfred is launched showing the definition for the selected text:

External

The External Triggers They offer a way for, using AppleScriptexternal applications tell Alfred what to do.

Continuing with the previous example, we add the external object with the Identifier what we want and we see how Sample Code is filled automatically. This is the code we will use to invoke the execution of the workflow from any external application:

Using the AppleScript Editor We can verify that the URL is indeed launched in Chrome:

File Action

The File Action triggers They are added to the results list so that, when a file is selected in Alfred, custom actions can be executed on it. For example, we are going to create a workflow that, by selecting a file (only .jpg or .png), copies it to a specific folder within our Dropbox folder. We start by adding the object File Action.

To define the type of files that are accepted, we drag a file of each of the types (in this case JPG and PNG):

For this example, we will also create a action of type RunScript (we will see it in the next post) which will be in charge of copying the file:

We join the Trigger with the Action…

…and we check that if we launch Alfred looking for a JPG or PNG type file, the new action appears, but not if we look for a TXT type file:

Contact Action

It’s not worth wasting a lot of time on this one since it’s practically identical to the one for the File Action but for specific fields of a contact. For example, by selecting the contact’s phone number we can initiate a FaceTime call to the user.

Fallback Search

Lastly, the Fallback Searches allow you to add custom workflows to the search dropdown. In our case, we are going to search for a term on the RAE website. To do this, as always, we add the object (in this case Fallback Search):

We define the action Open URL:

We link them:

Lastly and VERY IMPORTANT because it is not explained very well in the documentation and, if not, all this does not work well: Features -> Default Results -> Setup fallback results and we add our search Workflow Trigger -> Search {query} in the RAE.

Now, if we launch Alfred and write a word that it does not recognize, it will allow us to open it on the RAE website:

Inputs

The Inputs are the different input «values» that can be passed to a workflow. We have three types:

Keywords

The Keywords They are the most common or, rather, most commonly used input values ​​in Alfred. The operation is very simple: a word that causes a workflow to be launched. This word may or may not be accompanied by one or more parameters (separated by space). Let’s look at an example. We want typing «term» (without quotes) in Alfred and a path to open it in the Terminal application. To do this and as always, we add the object:

We add a action and we join the objects:

We believe that if we launch Alfred and write «term [path]» will open the Terminal application in the indicated path:

File Filter

As its name indicates, it allows you to filter the search for files that are passed as a parameter to the workflow. For example, we are going to filter so that only JPG type files appear:

If we launch Alfred and write «img», we will see how our filter appears:

ScriptFilter

Lastly, the Script Filters They are used to create workflows based on more complex scripts.

In the next post we will see how to do more «virgueras» things using Actions more complex and Outputs.

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *