Skip to content

Instantly share code, notes, and snippets.

@mlabbe
Created December 20, 2015 23:55
Show Gist options
  • Select an option

  • Save mlabbe/74cd42921d0c07a95edc to your computer and use it in GitHub Desktop.

Select an option

Save mlabbe/74cd42921d0c07a95edc to your computer and use it in GitHub Desktop.
Apple Bundle Writer in Python 3
import os
import shutil
import os.path
class AppleBundle:
def __init__(self, app_name, exe_path, icon_path, version_tuple=('1','0','0')):
self.app_name = app_name
self.exe_path = exe_path
self.icon_path = icon_path
app_name_nospaces = app_name[:]
app_name_nospaces.replace(' ', '')
exe_filename = os.path.basename(exe_path)
version_string = '.'.join(version_tuple)
self.info_plist = {
'CFBundleDisplayName': app_name,
'CFBundleExecutable': exe_filename,
'CFBundleName': app_name,
'CFBundleIdentifier': 'com.frogtoss.www.' + app_name_nospaces,
'CFBundleVersion': version_string,
'CFBundleShortVersionString': version_string,
'CFBundleSignature': 'FROG',
'CFBundleIconFile': os.path.basename(icon_path),
}
def write(self, out_root):
os.makedirs(out_root, exist_ok=True)
app_root = os.path.join(out_root, '%s.app' % self.app_name)
contents = os.path.join(app_root, 'Contents')
macos = os.path.join(contents, 'MacOS')
resources= os.path.join(contents, 'Resources')
os.mkdir(app_root)
os.mkdir(contents)
os.mkdir(macos)
os.mkdir(resources)
shutil.copy(self.exe_path, macos)
shutil.copy(self.icon_path, resources)
f = open(os.path.join(contents, 'Info.plist'), "wt", encoding='utf-8')
f.write('<?xml version="1.0" encoding="UTF-8"?>\n')
f.write('<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n')
f.write('<plist version="1.0">\n')
f.write('\t<dict>\n')
for key, value in self.info_plist.items():
f.write('\t\t<key>%s</key>\n' % key)
f.write('\t\t<string>%s</string>\n' % value)
f.write('\t</dict>\n')
f.write('</plist>\n')
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment