Generate and paste lowercase UUID automatically using Alfred workflow

Share this:

Generating UUIDs when needing to create a quick set of sample data is something I need to do quite often. With MacOS, there is a utility that comes out of the box that helps you generate UUIDs in uppercase. So what I would have to do is to (1) open terminal, (2) run the utility, (3) copy and paste the UUID (4) and convert the uppercase characters to lowercase. Wouldn’t it be great if I could generate and paste lowercase UUID automatically? 

With Alfred, that’s really easy!

But first, let’s also automatically transform the uppercase characters to lowercase.

Kens-MacBook-Pro:~ ken$ uuidgen
290FFCA8-A54F-4EA4-ADC4-8131894DD8D7

To transform 290FFCA8-A54F-4EA4-ADC4-8131894DD8D7 to lowercase, you will need to use the tr text replace utility to do so. But you actually also need to use the tr utility to remove a space and newline character that the uuidgen utility generates.

uuidgen | tr "[A-Z]" "[a-z]" | tr ' ' nil | tr '\n' nil

That is script you will need in your Alfred workflow. Executing the command in Terminal will yield the following result.

Kens-MacBook-Pro:~ ken$ uuidgen | tr "[A-Z]" "[a-z]" | tr ' ' nil | tr '\n' nil
4d528940-2305-4e3b-a54a-480946ae8d59nKens-MacBook-Pro:~ ken$

Creating the Alfred workflow

The following screenshot shows the completed workflow that I’ve configured in my Alfred app. It’s really pretty straight forward. The workflow: –

  1. Listens for the “uuid” keyword in Alfred.
  2. Runs the script as stated above
  3. Copies the result of the script to the clipboard and posts a notification on Mac OS.
uuidgen_alfred_workflow
Screenshot of the Alfred workflow for generating UUIDs

I will post the exported workflow at the later part of this post. But the following series of screenshots shows you the inner workings of the workflow so that you can easily create your own version as well. It will also serve as a great example for you to create any other workflows you want with Alfred.

1. Create the workflow’s input

First, right click on the empty canvas and select to add a new Keyword input as shown in the screenshot below.

alfred_workflow_inputs
Add a new keyword input

Go ahead and configure the Keyword input as per the screenshot below, or as you like it to be.

Configure the Keyword input with a ‘uuid’ keyword

Next, you will add a Run Script action with the script below. Here it is again so that you can copy and paste to your Alfred workflow.

uuidgen | tr "[A-Z]" "[a-z]" | tr ' ' nil | tr '\n' nil
Right-clicking on the Keyword object and select the Run Script action

You can just follow the configuration as the screenshot below.

Configuration of the Run Script action

Finally, you just need to add the Copy to Clipboard output.

Add the Copy to Clipboard output

If you want Alfred to automatically paste the generated UUID to your current active app, make sure the “Automatically paste to front most app” option is checked.

The script out will be stored as the {query} variable in Alfred. You can add any text before or after the {query} variable if you want too.

The post notification output is entirely optional. If you want to add it, just add another output after the Run Script block and configure it as per my example below.

Configure the Post Notification output

That’s it! You now have a new keyword trigger in Alfred that generates you a UUID into the clipboard and your app. Hopefully this also shows you how easy it is to create custom workflows in Alfred.

Let me just import it…

Of course I will provide the exported workflow here. But remember, you will still need to first have the uuidgen utility installed using homebrew as stated above.

Share this:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.