Created
October 6, 2012 20:00
-
-
Save ijprest/3845947 to your computer and use it in GitHub Desktop.
AutoHotkey (AHK) script to generate & paste a new GUID
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Exposes two hotkeys: | |
; - Win+G generates & pastes a new lowercase guid | |
; - Win+Shift+G generates & pastes a new UPPERCASE guid | |
; In both cases, the guid is left on the clipboard so you can easily paste it more than once. | |
; | |
GUID() | |
{ | |
format = %A_FormatInteger% ; save original integer format | |
SetFormat Integer, Hex ; for converting bytes to hex | |
VarSetCapacity(A,16) | |
DllCall("rpcrt4\UuidCreate","Str",A) | |
Address := &A | |
Loop 16 | |
{ | |
x := 256 + *Address ; get byte in hex, set 17th bit | |
StringTrimLeft x, x, 3 ; remove 0x1 | |
h = %x%%h% ; in memory: LS byte first | |
Address++ | |
} | |
SetFormat Integer, %format% ; restore original format | |
h := SubStr(h,1,8) . "-" . SubStr(h,9,4) . "-" . SubStr(h,13,4) . "-" . SubStr(h,17,4) . "-" . SubStr(h,21,12) | |
return h | |
} | |
; Win+G - Generate and paste a GUID | |
#g:: | |
guid := GUID() | |
StringLower, guid, guid | |
Clipboard := guid | |
SendInput,^v | |
return | |
; Win+Shift+G - Generate an UPPERCASE GUID | |
#+g:: | |
guid := GUID() | |
StringUpper, guid, guid | |
Clipboard := guid | |
SendInput,^v | |
return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great call. I knew it couldn't be that easy. I realized my needs were not as stringent to require a compliant GUID but still valued the the lack of external dependencies so I updated the documentation & expectation. Thanks for the feedback.