6 Digit Random Alphanumeric String Generator

Hey Guys!

I'd be grateful for a little help with this.

I am trying to create a 6 digit random alphanumeric string, much like what Obsidian generates when creating Link to blocks

For example dcf64c

In Obsidian, I use these as unique ID's to make connections between notes, pointing to a particular highlighted paragraph, but I am trying to replicate this feature in the note app, Craft.

All I need is a keyboard shortcut, which will generate a random 6 digit alphanumeric string enclosed by double brackets [[ ]] that copies to the clipboard and pastes into the note I'm working on.

I attempted creating an IOS Shortcut, but it is a bit hacky and slow and as a KM user, I'd prefer to use this instead.

Any suggestions would be greatly appreciated!

Thank you for your help in advance!

The simplest way I can think of to do this with native KM actions is to use the "Get Substring" action with the RandomUUID token:

Example Macro.kmmacros (1.6 KB)

If you need the letters to be lowercase, as your example suggests you might, you can always run the LocalResult variable through the lowercase filter action before pasting it.

3 Likes

This is a smart way!

I did a search online and found this one line perl code works great.
image

perl -e '@c=("A".."Z","a".."z",0..9);$p.=$c[rand(scalar @c)] for 1..6; print "$p\n"'

I put two lines there so that if you want to change the length of the string, you know where to make the change.

Source (the sample codes did not work for me, I found the perl cmd in one of the comments):

2 Likes

Thank you for this! You made it so simple!!! Really appreciate the help! :grinning:

1 Like

Thanks Martin! Ive gone with @gglick solution, but will keep this filed as could be useful in the future! Thank you :+1: