Skip to content

Instantly share code, notes, and snippets.

@cspickert
Created March 18, 2011 00:19
Show Gist options
  • Save cspickert/875406 to your computer and use it in GitHub Desktop.
Save cspickert/875406 to your computer and use it in GitHub Desktop.
A short PyObjC script to set git-config user parameters via the Address Book Framework.
#!/usr/bin/python
from objc import YES, NO, NULL
from Foundation import *
from AddressBook import *
import os
# Set the path to git
GIT = "/usr/local/bin/git"
# Get the current user's address book record
myPerson = ABAddressBook.sharedAddressBook().me()
# Get the user's full name
fullName = ' '.join(map(myPerson.valueForProperty_, [kABFirstNameProperty, kABLastNameProperty]))
# Get the user's primary email
emailProperty = myPerson.valueForProperty_(kABEmailProperty)
identifier = emailProperty.primaryIdentifier()
email = emailProperty.valueForIdentifier_(identifier)
# Set the appropriate settings using git-config
os.system("%s config --global user.name '%s'" % (GIT, fullName))
os.system("%s config --global user.email '%s'" % (GIT, email))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment