Created
July 4, 2011 10:47
-
-
Save ssbarnea/1063200 to your computer and use it in GitHub Desktop.
osx-add-to-path
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
#! /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