Skip to content

Instantly share code, notes, and snippets.

@ssbarnea
Created July 4, 2011 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssbarnea/1063200 to your computer and use it in GitHub Desktop.
Save ssbarnea/1063200 to your computer and use it in GitHub Desktop.
osx-add-to-path
#! /usr/bin/env python
import os, sys, plistlib
# Warning this solution works with 10.6+ (including 10.7)
# On 10.5 the apps executed via Spotlight are not going to see the new PATH
f = os.path.expanduser("~/.MacOSX/environment.plist")
try:
dic = plistlib.readPlist(f)
except Exception as e:
dic = {}
dic['PATH']="/usr/bin:/bin:/usr/sbin:/sbin" + ":/usr/local/bin"
plistlib.writePlist(dic,f)
else:
if 'PATH' not in dic:
dic['PATH'] = "/usr/bin:/bin:/usr/sbin:/sbin"
if '/usr/local/bin' not in dic['PATH'].split(":"):
dic['PATH'] += ":/usr/local/bin".
plistlib.writePlist(dic,f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment