Skip to content

Instantly share code, notes, and snippets.

@dougpagani
Created August 27, 2018 04:34
Show Gist options
  • Save dougpagani/a2dcccaa26cd97b36a85599fbcadf173 to your computer and use it in GitHub Desktop.
Save dougpagani/a2dcccaa26cd97b36a85599fbcadf173 to your computer and use it in GitHub Desktop.
Get macOS password from the 'security' command in python
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