Skip to content

Instantly share code, notes, and snippets.

@mlhDevelopment
Forked from ijprest/guidgen.ahk
Last active November 5, 2024 13:58
Show Gist options
  • Save mlhDevelopment/6ef44209afbccbcd3a80fcf182b17b2a to your computer and use it in GitHub Desktop.
Save mlhDevelopment/6ef44209afbccbcd3a80fcf182b17b2a to your computer and use it in GitHub Desktop.
AutoHotkey (AHK) v2 script to generate & paste a 32 character random hex string and format it like a GUID (i.e. a psuedo GUID)
; Exposes two hotkeys:
; - Win+G generates & pastes a new lowercase psuedo guid
; - Win+Shift+G generates & pastes a new UPPERCASE psuedo guid
; In both cases, the psuedo guid is left on the clipboard so you can easily paste it more than once.
; NOTE: this is technically not a GUID as defined by RFC 9562 since it does not attempt to use the
; recommended algorithms and no timestamp is embedded. It is only a 128 bit random number formatted
; as 32 hex values in the 8-4-4-4-12 GUID format.
; Win+G - Generate and paste a psuedo GUID
#g::
{
pGuid := ""
Loop 8 {
pGuid := pGuid . Format("{:x}", Random(0, 15))
}
pGuid := pGuid . "-"
Loop 4 {
pGuid := pGuid . Format("{:x}", Random(0, 15))
}
pGuid := pGuid . "-"
Loop 4 {
pGuid := pGuid . Format("{:x}", Random(0, 15))
}
pGuid := pGuid . "-"
Loop 4 {
pGuid := pGuid . Format("{:x}", Random(0, 15))
}
pGuid := pGuid . "-"
Loop 12 {
pGuid := pGuid . Format("{:x}", Random(0, 15))
}
A_Clipboard := pGuid
Send pGuid
}
; Win+Shift+G - Generate an UPPERCASE psuedo GUID
#+g::
{
pGuid := ""
Loop 8 {
pGuid := pGuid . Format("{:X}", Random(0, 15))
}
pGuid := pGuid . "-"
Loop 4 {
pGuid := pGuid . Format("{:X}", Random(0, 15))
}
pGuid := pGuid . "-"
Loop 4 {
pGuid := pGuid . Format("{:X}", Random(0, 15))
}
pGuid := pGuid . "-"
Loop 4 {
pGuid := pGuid . Format("{:X}", Random(0, 15))
}
pGuid := pGuid . "-"
Loop 12 {
pGuid := pGuid . Format("{:X}", Random(0, 15))
}
A_Clipboard := pGuid
Send pGuid
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment