Photo by Markus Spiske on Unsplash

Generating data with Alfred Workflows — Personal Productivity

Jan-Hendrik Kuperus

--

Let’s kick down the door and get right to the point: whether you are designing, developing or testing a piece of software, chances are you’ll need data. Sometimes you just need it to show what a contract would look like, or as an example edge case in a (unit) test. Other times it needs to be as representative of reality as possible.

Take for example UUIDs. It’s hard to find software these days that does not in some way use them. In documentation you might be okay with seeing 00000000-0000-0000-0000–000000000000 as an example, but in tests this value is pretty useless. Unless you want to explicitly test collisions, you will probably quickly tire of using the same UUID over and over again. But how do you generate a new one on the spot when you need it? Well that’s where Alfred’s workflows provide an awesome way to generate whatever data you need.

If you’re reading this article and are unfamiliar with Alfred, please take a few minutes to read my post Introducing Alfred. Then come back here and build your first workflows.

Workflows

Alfred has a very strong, visual engine for building workflows which can be activated by a myriad of triggers. Options include a hotkey, an AppleScript call from another application, actions on a file and also the use of a keyword in Alfred’s search bar. Most of my workflows use this Keyword trigger.

The workflows can be grouped in “sheets”, which you can create with the + on the bottom of the Workflow panel in Alfred. When you create a workflow, you can enter some metadata for it.

Workflows can later be exported and shared and to be able to keep them apart, each workflow has a bundle ID and info on its creator. While this is great, workflows are exported in a binary file format, making them terribly unsuited for storing inside any type of source control.

That said, let’s dive into the actual workflows themselves and see how to create them.

UUID

In most of my projects, UUIDs are literally everywhere. This means I regularly need just some sort of UUID to test something. My Alfred UUID Workflow allows me to type ⌘-Space uuid
and have fresh UUID available in my pasteboard, ready to insert anywhere with ⌘V.

Alfred showing the UUID workflow’s description

The workflow itself is really simple. These data generators are basically all a Keyword-input node connected to a Run Script-node. This effectively tells Alfred to run a bit of shell scripting whenever you type the keyword of the workflow (in this case uuid). Below you can see how to make this simple workflow.

Creating a tiny workflow

When you’re creating a node, Alfred opens a dialog for the configuration of that node. In the video above, I’ve left that out for brevity. The configuration for the UUID-keyword node looks like this:

Configuration of UUID Keyword-node

Here’s a rundown of what you can configure:

  • The value in the keyword field is what you will have to type into the Alfred Search box to match this workflow.
  • The dropdown box with No Argument signifies that the node won’t match when you type something after uuid. Other options here are Argument Optional and Argument Required. When using an argument, its value gets propagated to the next node in the workflow, usually named query.
  • The title field is the large text shown in the Alfred results box.
  • The subtext field is optional and if present is shown beneath the title in the results box.
  • The icon box here is empty, but you can drop any image file there to use it as an icon in the results box.

Something similar appears for the configuration of the Run Script node, which in this case will have to look like this:

Configuration of the Run Script node for UUID workflow

Here again I’ll run you through the values you see:

  • The language indicates which interpreter should be used to run the script in the large text field. Options include zsh, php, ruby, python, perl and osascript.
  • The second box indicates whether the input of the node (which can be the argument or output of the previous node) should be included as a command line parameter, or replaced in the script as a template variable.
  • The third dropdown allows you to specify whether multiple invocations of this node should wait for the previous one to complete (sequentially) or run in parallel (concurrently).
  • The large text field is where you can write the actual script to execute. Here it uses uuidgen and transforms it to lowercase and finally puts it in the MacOS pasteboard. You can literally write any script you want here.

That’s actually all there is to the UUID workflow. Now, when you type uuid in Alfred’s search bar and press enter, you will have a freshly generated UUID stored in your pasteboard. Simply press ⌘V to use it wherever you need.

Hashes, timestamps and IP addresses

The other three data generation workflows are basically the same as the one described above. So for brevity’s sake and the prevention of your boredom, I’ve exported my sheet of Data Generation workflows for you to download. Go ahead, download them, use them, enhance them. If you think of any other cool data-generators, please let me know and I might just add them to the sheet.

Thanks for reading and have fun generating all sorts of stuff :)

— JH

--

--

Jan-Hendrik Kuperus

Hi! I’m the Founder and Director of Yoink. I love writing code, tweaking it, beautifying it. I'm an all-round coder and a Professional Amateur Baker 😁🎂