Created
May 8, 2016 15:48
-
-
Save drosenstark/245a4d4e545ce96969a57dee9cef6d52 to your computer and use it in GitHub Desktop.
Unique ID to Clipboard for Workflowy (or whatever), OSX
This file contains 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
#!/usr/bin/env ruby | |
# uiqueid generates a 4 character unique ID and puts it in the clipboard | |
# configurable variables | |
prefix = "WF-" | |
totalChars = 4 | |
startPoint = 97 # use 65 for upper, 97 for lower | |
def pbcopy(input) | |
str = input.to_s | |
IO.popen('pbcopy', 'w') { |f| f << str } | |
str | |
end | |
def pbpaste | |
`pbpaste` | |
end | |
if __FILE__ == $0 | |
thing = (0...totalChars).map { (startPoint + rand(26)).chr }.join | |
pbcopy "#{prefix}#{thing}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is pseudo-unique. Chances of collision are 26totalChars, so in this example it's 1 in 456,976.