Created
August 27, 2018 04:34
-
-
Save dougpagani/a2dcccaa26cd97b36a85599fbcadf173 to your computer and use it in GitHub Desktop.
Get macOS password from the 'security' command in python
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
import subprocess | |
import re | |
# Grab password from macOS keychain | |
def grab_gh_password(): | |
invocation = ['security', 'find-internet-password', '-gs', 'github.com'] | |
block = subprocess.Popen(invocation, stdout = subprocess.PIPE, stderr = subprocess.PIPE) | |
lastline = block.stderr.read().strip().decode("utf-8") | |
parsed_password = re.sub('password: "(.*)"', '\\1', lastline) | |
return parsed_password |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment