Instantly Create Gmail Addresses for Testing with a Keyboard Shortcut on Mac OS

Josh Stillman

March 8, 2021

Build

When developing new features, it can be useful to be able to create new, unique, working email addresses for testing. For example, say you want to repeatedly test a sign-up flow end-to-end, and you need a new, unique email address each time through the flow. Furthermore, you’d like to use a real, working email address to verify the behavior of a confirmation email that gets sent after signing up. How can we easily accomplish this?

If you have a Gmail or Google Workspace (formerly G Suite) email address, you’re in luck! One of Gmail’s coolest under-the-radar features is the ability to create task-specific email addresses by adding a plus sign followed by additional characters to your email address. So, if your email address is [email protected], you can sign up with [email protected], and emails to [email protected] will reach your inbox. This makes it easy to repeatedly create new, unique, working addresses for testing!

But if you do this a lot, it becomes mentally draining to keep track of which email addresses you’ve already used and come up with new addresses on the fly. You’ll have to keep track of whether you’ve already used [email protected] or should instead be on [email protected], for example. Instead, let’s automate it!

With some built-in Mac OS tools, it’s possible to automatically create new, unique Gmail addresses with a handy keyboard shortcut to speed up our smoke testing. First, we’ll use the Mac OS Automator application to create a script to generate new email addresses using the current system time. Then we’ll attach that script to a keyboard shortcut in our system keyboard preferences.

Mac OS ships with the Automator program that allows you to create scripts using JavaScript or your shell, and these scripts can output text. In Automator, select New, then choose Quick Action.

Automator Quick Action

On the left hand pane, select Utilities, then Run JavaScript or Run Shell Script.

On the top pane, select Workflow receives no input in any application. Also select the Output replaces selected text checkbox.

In the Run JavaScript dialog below, create a script that will interpolate the system time in milliseconds into your Gmail address after the + sign. Using ES6 template literals, you can have the function return `bob.smith+${new Date().getTime()}@gmail.com`, which will return an email in the format [email protected]. Make sure not to check Show this action when the workflow runs, otherwise Automator will show a pop-up each time. Then, save and name your Automator action.

You can also use Automator to execute shell scripts, which opens up all kinds of possibilities. The equivalent shell script here (in seconds) would be printf "bob.smith+%[email protected]" $(date +%s).

Keyboard Shortcut

Next, open System Preferences, choose Keyboard, then Shortcuts. In the left-hand pane, choose Services. You should see the Quick Action you created with Automator as an option in the right-hand pane. Add a memorable keyboard shortcut, then click the checkbox to activate. (I chose Control + Option + Command + C, but you might want to investigate setting up a Hyper Key for things like this instead.)

Now, give your keyboard shortcut a try!

This is one simple example of how to use scripting, Mac OS Automator, and keyboard shortcut mappings to automate simple tasks and speed up your development experience. But these tools open up tons of other possibilities. Got any cool ideas of your own? Let us know in the comments!

About the author

Josh Stillman

Web Development, Music, Politics, etc.

SHARE VIA

Stay in the loop

Keep up to date with our newest products and all the latest
in technology and design.
Keep up to date with our newest products
and all the latest
in technology and design.

Other blog posts

Helping to Change the Face of Fintech

Giant Machines leads FinTech Focus – a program designed for rising first year college students who have an interest in finance, computer science, and technology.

Enablement, Upskilling, and the Meaning of Learning

The foundation of Giant Machines is in learning, education, and growth, whether that's for software engineers or developing other helpful skills. Here's how it helps us—and our clients.

How We Celebrated Our Company Culture with Giant Machines Week

Giant Machines week celebrates our company's community and culture with presentations, workshops, and a yacht ride around the Hudson River.

Company

Learn more about us here at Giant Machines and how you can work with us.

What we do

We leverage best-in-class talent to create leading edge digital solutions.
services

Innovate

Know your next move

Build

Develop beautiful products

Learn

Enrich your tech knowledge

Our work

Learn more about our partnerships and collaborations.

Our perspective

Stay up to date with the latest in technology and design.

SUBSCRIBE