Generate passwords

UPDATE: I have tried to optimise the macro with @peternlewis comments from below. So now it does not generate duplicates.

In my line of work I am sometimes asked to generate a list of 10.000 or more unique "passwords" for a mail-merge campaign.
So I created a macro to help me with it.

I used the command line tool pwgen which I install with brew.
You can install Homebrew from here:
Then run the command brew install pwgen

This macro could use some optimisation. When I generate a lot of numbers then some duplicates are present.
At the moment I the use BBEdit to remove duplicates afterwards but I am sure it somehow could be done in the macro. But I have not made it that far yet.

Keyboard Maestro 8.0.2 “Generate passwords” Macro

Generate passwords.kmmacros (17 KB)

I assume from your comments you wanted some advice on the macro?

Is there a reason the initial If Then Else With Symbols action is not placed before the Switch instead of duplicated into each branch of the macro? It appears identical to me, and duplication is always a worry. Same for the Trim Whitespace.

Similarly, the Switch on Case could be done after that or after the Switch statement, rather than duplicated in each branch of the Switch on Ambiguous.

Then there would be nothing left in the second branch of the Switch on Ambiguous, so it can become an If Then Else with just one side.

This would make it clearer too, since your macro would then be:

  • Ask for details
  • Execute brew
  • Trim White Space
  • If Ambiguous
    • Remove Ambiguous characters
  • Adjust Case

As for removing duplicates, you can do this:

The passwords will not be sorted, which may be undesirable, but sorting is generally the first step to removing duplicates. And alternative would be to process through them each and only keep ones that hadn't been seen yet.

Although I have to wonder what length your passwords are - you should not be ever getting duplicates with 32 character passwords. The chance of even just 32 digits having a duplicate in 10,000 numbers would be 1 in 10^24.

If you're getting duplicates, unless you are using much smaller numbers of characters, or you are deliberately seeding your random number generated, I'd say your password generation is broken.

1 Like

Hi Peter

Thanks for the input. Will look into optimising the macro later.

The start value is just 32 in length. Sometimes I am asked to generate 30.000 passwords in 6 characters in length.
And here duplicates occur.
The passwords I need to generate for a job like this is more codes to see if you have won a price or something like that in a mail campaign we do for our customers.