Created
January 26, 2021 16:11
-
-
Save bbenne10/dbc13c2402d3a06d6d364c121e690f0f to your computer and use it in GitHub Desktop.
pass applescript
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
property defaultPass : "someDefaultPass" | |
property clearAfter : 45 | |
property passPath : "pathToPass" | |
property passStore : "/Users/<userName>/\\.password-store\\/" -- backslash escaping '.' helps sed later but doesn't affect find. | |
on run {input, parameters} | |
try | |
set availablePasswords to every paragraph of (do shell script "find " & passStore & " -name '*.gpg' | sed -E 's;^" & passStore & "(.+)\\.gpg$;\\1;'") | |
set entity to choose from list availablePasswords with prompt "Which password?" default items {defaultPass} | |
set pw to do shell script passPath & " " & entity & " | head -n 1" | |
set oldClipboard to (the clipboard) | |
set the clipboard to pw | |
-- Wait until clipboard changed then close notification | |
repeat with secsLeft from 0 to clearAfter | |
if (the clipboard) is equal to pw then | |
-- set event handlers script path to (path to me) | |
display notification "Password copied to clipboard (" & (clearAfter - secsLeft) & " secs left)" with title "Password Store" | |
delay 1 | |
else | |
exit repeat | |
end if | |
end repeat | |
on error errMsg | |
display dialog errMsg with title "Error" with icon stop | |
end try | |
-- Clear clipboard | |
set the clipboard to oldClipboard | |
return input | |
end run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment