Easily generate UUID using Alfred workflow and uuidgen
Generating UUIDs when needing to create a quick set of sample data is something I need to do quite often. On MacOS, there isn’t a utility that comes out of the box that helps you generate UUIDs. But thankfully with homebrew, you can easily install uuidgen on MacOS. uuidgen is a rather useful utility that’s available in Linux OS that does exactly what its meant to do.
To install uuidgen with homebrew, simply use the following command.
brew install uuidgen
If you don’t already have homebrew installed on your MacOS, just following the instructions here to install it. Or just simply run the following command in Terminal.
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
To generate a uuid with uuidgen, just simple use the utility.
Kens-MacBook-Pro:~ ken$ uuidgen 290FFCA8-A54F-4EA4-ADC4-8131894DD8D7
The only thing about uuidgen is that it generates the uuid with the alphabet characters in caps. Example: 290FFCA8-A54F-4EA4-ADC4-8131894DD8D7. So if want it to be in lower case characters, 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
So that is the 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: –
- Listens for the “uuid” keyword in Alfred.
- Runs the script as stated above
- Copies the result of the script to the clipboard and posts a notification on Mac OS.
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.
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.