Bypass - Shortcuts Support for Stream Deck

A few weeks ago I released version 1 of an Alfred workflow called Bypass. I created it to help use Apple’s Shortcuts app on the Mac. I have been continuing to expand the functionality, and have now released v1.1 with many new features.

One of the areas I spent a bit of time working on was a way to make Shortcuts easier to use with the Elgato Stream Deck, and in this post I’m going to walk through how Bypass now supports setting up Shortcuts on the Stream Deck.

Get a Copy of Bypass

In order to make use of Bypass for this purpose, there are a number of prerequisites:

  1. You must be running macOS Monterey or higher - this is the first version of macOS that supports Shortcuts.
  2. You must have Alfred installed, and be a licensed Alfred PowerPack user - Alfred workflows require the PowerPack license.
  3. You must have an Elgato Stream Deck (physical or mobile app).

When you have all of the prerequisites in place, you can get a copy of Bypass.

Open the downloaded file to install the workflow in Alfred.

Shortcuts Icons

On the Stream Deck, you can assign practically any image that you like for a button, but for a button that triggers a Shortcuts shortcut, it is often nice to have an image that matches the icon specified in Shortcuts for the shortcut. To extract the icon I created a shortcut that can be run standalone allowing you to select which icons you wish to extract, or with input allowing you to specify exactly which shortcut’s icon to extract.

Bypass provides the sciconextractor keyword that will open to the latest copy of the shortcut for download.

If you wish to use the shortcut standalone, you are welcome to do so, and can download it from the link provided in this file.

When you install the shortcut, you will be prompted to specify a folder location where the shortcut should save extracted icons to. The icon files will be saved as PNG files in this folder, with the name of the shortcut. It will overwrite any existing file of the same name.

When run stand alone, you can either export icons for all shortcuts, or for shortcuts you select from a list (of all available shortcuts).

Bypass can be set to automatically extract the icon for a shortcut when it is preparing Stream Deck use. By default this option is enabled, but you can toggle it on of off in Alfred by entering the scasdauto keyword.

If you have it enabled, but do not have the shortcut installed to extract the icon, then you will be prompted to install it, and taken to the installation page. The icon would of course not be generated on that invocation, but once installed, you can extract the icon via Bypass by entering scicon in Alfred and selecting the shortcut whose icon you want to be extracted.

Running a Shortcut

To run a shortcut, we are going to use the System: Open action for the Stream Deck. This action can be used to open files and applications.

We are going to use it to open a special launcher script included with Bypass. This script takes the name of the shortcut as a parameter, and when opened, will run that shortcut. While that may sound a little complicated, Bypass makes it super easy.

Enter whatever title you wish into the Title field for the System: Open action. You can even leave it blank if you wish. Now, place your cursor in the App / File field and type in scsd+.

This is a snippet trigger for a Bypass flow, and it will then pop up a list of shortcuts in the Alfred window for your to choose from. Type in some text to filter the list and select the shortcut you wish to trigger from the Stream Deck.

Here I’m going to select my example shortcut, “Mac3”. This then populates the App / File field with the following text for me:

"/Users/stephen/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.48C31CBB-55AF-4568-991B-1890CCA5A82C/run_shortcut.sh" "Mac 3"

The path to the run_shortcut.sh file is created based on the Alfred preferences location (held in the Alfred environment variable $alfred_preferences) and the unique workflow ID (held in the Alfred environment variable $alfred_workflow_uid) associated with Bypass.

The parameter that follows is the name of the shortcut to be run. No need for lots of files that all effectively do the same thing. Bypass simply gives you a file to handle this and a text expansion to populate it.

If you have downloaded the icon extractor workflow and have auto extraction enabled, you should now also find that the shortcut’s icon is available in your specified folder, and that you can set the icon for your Stream Deck action/button to that of the shortcut.

My button and Stream Deck now look like this:

When I press the button on my Stream Deck, the example shortcut is triggered and an emoji is displayed in a show result window.

Running a Shortcut With Input

It is also possible to run a shortcut and pass it some text input at the same time. To do this, we follow the same sort of steps as before, except we invoke a different snippet - scsdi+.

This time after selecting a shortcut to run, we then get prompted to enter some text to pass to the shortcut.

Selecting “Mac 1” as the shortcut and “Hello World” as the additional information to pass through then results in the following command in the App / File field.

"/Users/stephen/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.48C31CBB-55AF-4568-991B-1890CCA5A82C/run_shortcut_with_input.sh" "Mac 1" "Hello World"

The key differences here are:

  1. The Bypass script file now being run is run_shortcut_with_input.sh rather than run_shortcut.sh.
  2. I chose a different shortcut - one that accepts input.
  3. The information to pass to the shortcut appears as an additional parameter for the script.

When run from the Stream Deck, the shortcut being run outputs “Just received this: “ followed by any text if was passed, into a show results window.

Running a Custom Workflow to Run a Shortcut

Those two give us a solid starting point for running shortcuts from the Stream Deck. Most users will use the first option - a shortcut without input, gathering any required input in the shortcut itself. A subset of these users will choose to run some of their shortcuts from Alfred (via Bypass), passing in a string of text as input. But, there is another group of users. The ones who like to go that bit further.

As anyone who has taken a look at my workflow for Drafts (Doctor Drafts) might know, I like to make my Alfred workflows extensible and that is why I try to include external triggers where possible, and have done so in Bypass. External triggers can be utilised from within workflows and also external to Alfred (hence the name), via an AppleScript call.

In this section I will walk through how you can create a custom Alfred workflow, built on top of Bypass, and then trigger that from a button on the Stream Deck.

First of all, I will create a basic flow example. It is made of three linear blocks.

The first block is an external trigger this is what we are going to call from the Stream Deck. Take note of the trigger Mac 1 Now, and the bundle ID com.thoughtasylum.bypassexamples for the Alfred workflow. We will make use of these shortly as they uniquely identify the flow and we are in effect going to run the same AppleScript - just via a bit of a scenic route.

The next block in the flow sets up the name of the shortcut we are going to run (“Mac 1”) in variable shortcut2run, and the data we are going to pass to it. in this case a string for time and date that Alfred is going to generate for us. This is just an example,and you could implement a more complex script in a flow like this to do whatever you require, and pass the results on to a shortcut.

The final block is a call to an external trigger in another workflow - the Bypass workflow. The trigger being called is scruni, and takes the input it received and passes this on to a shortcut specified in the variable shortcut2run, that is then run.

If I run the following AppleScript, this will trigger an output such as the one below.

tell application id "com.runningwithcrayons.Alfred" to run trigger "Mac 1 Now" in workflow "com.thoughtasylum.bypassexamples" with argument "test"

Unfortunately, you can’t just throw AppleScript into the System: Open action in the Stream Deck. In fact I tried several methods to work around this, but kept coming unstuck when the macOS security permission prompt kept being blocked because the request was running in the background. Fortunately I did find a way around this that seems to be pretty performant.

Just like the snippets used previously, I created a snippet aesd+ that you can type into the App / File field and generate the appropriate command.

The first prompt received is for the event trigger, so we enter “Mac 1 Now”.

The second prompt received is for the bundle ID, so we enter “com.thoughtasylum.bypassexamples”.

The resulting command in the field that is generated from this is as follows:

"/Users/stephen/Library/Application Support/Alfred/Alfred.alfredpreferences/workflows/user.workflow.48C31CBB-55AF-4568-991B-1890CCA5A82C/alfred_external.app" --args "Mac 1 Now" "com.thoughtasylum.bypassexamples"

Note that this is not specifying a specific shortcut. The custom flow in Alfred is doing that. But, this means that this will never automatically extract an icon, because there is no directly associated shortcut.

When the command is executed from the Stream Deck, the result is just the same as if we had run the AppleScript directly. Bypass handles the complexity of generating the command and providing the runner.

Summary

We have now gone through three methods that can be used to trigger shortcuts from Alfred in increasingly complex and powerful ways. As I noted above, the first method is going to cover the majority of use cases, but there is enough flexibility in Bypass to make adding more advanced shortcuts calls to your Stream Deck.

I hope that you found this post useful in explaining how Bypass can help you get even more value from your Elgato Stream Deck. Bypass is quickly growing in capability, and I expect there will be more updates in the future to keep an eye out for.

Author: Stephen Millard
Tags: | alfred | shortcuts | stream deck |

Buy me a coffeeBuy me a coffee



Related posts that you may also like to read