Skip to content

Instantly share code, notes, and snippets.

@pnasrat
Created April 21, 2011 19:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pnasrat/935329 to your computer and use it in GitHub Desktop.
Save pnasrat/935329 to your computer and use it in GitHub Desktop.
bob's install-name-tool.py
import macholib
def install_name_tool(fn, new_id=None, changedict=None):
m = macholib.MachO(fn)
if new_id:
m.rewriteInstallNameCommand(new_id)
if changedict:
m.rewriteLoadCommands(changedict)
m.save()
if __name__ == '__main__':
import sys
args = sys.argv[1:]
def err():
print >>sys.stderr, 'Usage: %s [-change old new] ... [-id name] input' % (sys.argv[0],)
raise SystemExit
if not args:
err()
new_id = None
fn = None
changedict = {}
args = iter(args)
try:
for arg in args:
if arg == '-change':
changedict[args.next()] = args.next()
elif arg == '-id':
new_id = args.next()
else:
fn = arg
if list(args):
raise StopIteration
break
else:
raise StopIteration
except StopIteration:
err()
install_name_tool(fn, new_id, changedict)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment