1 /* mac-fix-env: A small utility to pick up the shell environment on MacOS X
2 and insert it into the file ~/.MacOSX/environment.plist
4 Copyright (C) 1989, 1993, 2005, 2008 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA.
24 Run from command line (in Terminal) once or whenever path changes:
26 /Applications/Emacs.app/Contents/MacOS/bin/mac-fix-env
28 (change initial part to where you installed Emacs).
31 #import
<Foundation
/Foundation.h
>
34 int main
(int argc
, char *argv
[])
36 NSAutoreleasePool
*pool
= [[NSAutoreleasePool alloc
] init
];
37 NSMutableDictionary
*envPlist
;
38 NSString
*file
= [[NSHomeDirectory
()
39 stringByAppendingPathComponent
:@".MacOSX"
]
40 stringByAppendingPathComponent
:@"environment.plist"
];
41 NSString
*path = [NSString stringWithCString
: getenv("
PATH"
)];
43 envPlist
= [[NSDictionary dictionaryWithContentsOfFile
: file
] mutableCopy
];
47 NSString
*dir = [file stringByDeletingLastPathComponent
];
48 envPlist
= [NSMutableDictionary dictionaryWithCapacity
: 5];
50 if ([[NSFileManager defaultManager
] fileExistsAtPath
: dir] == NO
)
52 if ([[NSFileManager defaultManager
] createDirectoryAtPath
:dir
55 NSLog
(@"
:\nCould not create directory at
'%@'; aborting."
,dir);
61 [envPlist setObject
: path forKey
: @"
PATH"
];
63 if ([envPlist writeToFile
: file atomically
: YES
] == NO
)
65 NSLog
(@"
:\nCould not write file at
'%@'; aborting."
, file
);
69 NSLog
(@"
:\nWrote file to
'%@'.
\nPlease inspect it to make sure
PATH is correct."
, file
);