Skip to content

Instantly share code, notes, and snippets.

@surajsau
Created May 24, 2020 10:17
Show Gist options
  • Save surajsau/99771dd38cbfde33d294a176e3601a7f to your computer and use it in GitHub Desktop.
Save surajsau/99771dd38cbfde33d294a176e3601a7f to your computer and use it in GitHub Desktop.
Applescript for Password Generation
on generatePassword()
set chars to {}
set shuffledChars to {}
-- (1)
repeat with index from 1 to 15
if index is less than 5 then
set chars to chars & some item of lowercase
else if index is less than 10 then
set chars to chars & some item of uppercase
else if index is less than 13 then
set chars to chars & some item of numericals
else
set chars to chars & some item of symbols
end if
end repeat
-- (2)
repeat 15 times
-- (3)
set randomIndex to random number from 1 to (count chars)
set randomChar to item randomIndex of chars
-- (4)
set shuffledChars to shuffledChars & randomChar
-- (5)
set reducedChars to {}
repeat with index from 1 to (count chars)
if index is not equal to randomIndex then
set reducedChars to reducedChars & item index of chars
end if
end repeat
set chars to reducedChars
end repeat
-- (6)
return shuffledChars as text
end generatePassword
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment