Skip to content

Automating UUID and Key Generation with Alfred Workflows

There are those tasks that you have to do regularly enough that it becomes irritating to do them manually but not often enough that they become second nature. This is where Alfred comes in handy. By creating workflows and snippets, you can automate these repetitive tasks and save yourself a lot of time and effort.

Two of the tasks that fall into this catergory for me is generating UUIDs and keys. I use these in various applications and systems, and having a quick way to generate them is a real time-saver. So I built an Alfred workflow to handle them.

View Screenshot

We start with a keyword trigger which in my case is uuid and then we use the uuidgen command to generate the UUID. The output is then copied to the clipboard for easy access, the result also gets posted as a notification.

Terminal window
uuidgen | tr '[:upper:]' '[:lower:]'

In action you can see how easy it is: How it works screenrecording

and you get a notification to confirm the UUID has been copied: The notification

The process for generating a key is similar to that of generating a UUID. We use a different keyword trigger, in this case key, and a different command to generate the key. The output is again copied to the clipboard and a notification is displayed.

Terminal window
openssl rand -hex 32

However, Sometimes we don’t want the key as a hex string. In that case, we can use the base64 command to generate a base64-encoded key instead.

Terminal window
openssl rand -base64 32

So I can easily switch between different key formats as needed I could have created seperate workflows for each format but I prefer to keep things simple and have a single workflow that uses an argv to work out which format to use. So I can use:

  • key or key hex for hex. ae71a2bbbed9fc038f9c9ca2f5f4b78012e8dc557a315c1f68ae0b5f72dca41b
  • key base for base64. 0RrPh8vi94Um0POAuZ0saqmQ9ZAyFYiZxnhi/vR6WrM=
Terminal window
case "$1" in
hex|"") # default to hex if no arg
openssl rand -hex 32
;;
base|base64)
openssl rand -base64 32
;;
*)
echo "Unknown option: $1 (use 'hex' or 'base')"
;;
esac

Alfred is my current favorite application of this type, and I have been using it for a very long time (I first paid for it in 2014), I also credit Alfred with finally making MacOS click for me. Screenshot of receipt However, there are other similar applications available, such as LaunchBar and Raycast, which offer similar functionality. The concepts and workflows described in this guide can be adapted to work with these other applications as well.

In conclusion, using Alfred to generate UUIDs and keys can greatly enhance your productivity and streamline your workflow. By leveraging the power of Alfred’s automation capabilities, you can save time and effort on repetitive tasks, allowing you to focus on more important aspects of your work. Whether you stick with Alfred or explore other launch bar applications, the principles outlined in this guide can help you create efficient workflows tailored to your needs.