Skip to content

Instantly share code, notes, and snippets.

@Draknek
Last active Jul 21, 2022
Embed
What would you like to do?
Normally if you zip a .app directory on Windows and unzip it on Mac OS X, it won't run. This tool creates a zip file that should have the correct executable flags set to work correctly.
#!/usr/bin/env python
import os
import sys
import time
import zipfile
if (len(sys.argv) != 2):
print "Wrong number of arguments - needs 1"
sys.exit()
appdir = sys.argv[1]
if (appdir[-4:] != ".app"):
print "Error: " + appdir + " is not a .app file."
sys.exit()
dir = os.path.dirname(appdir)
if (not os.path.exists(appdir)):
print "Error: " + appdir + " does not exist."
sys.exit()
os.chdir(dir)
appdir = os.path.basename(appdir)
zipname = appdir[0:-4] + ".zip"
searchname = appdir + "/Contents/MacOS/"
zip = zipfile.ZipFile(zipname, 'w', zipfile.ZIP_DEFLATED)
for root, dirs, files in os.walk(appdir):
for file in files:
filename = os.path.join(root, file)
if (filename[0:len(searchname)] == searchname):
f = open(filename, 'r')
bytes = f.read()
f.close()
info = zipfile.ZipInfo(filename)
info.date_time = time.localtime()
info.external_attr = 0100755 << 16L
zip.writestr(info, bytes, zipfile.ZIP_DEFLATED)
else:
zip.write(filename)
zip.close()
print "Created " + zipname
@houkanshan
Copy link

houkanshan commented Oct 30, 2020

Thanks Draknek! I ported it to python3 and made an exe file here: https://gist.github.com/houkanshan/3c02a8f4487b2d343ae23522c9abe4f0

@duolabmeng6
Copy link

duolabmeng6 commented Jul 21, 2022

Could you tell me how to keep the soft connection when decompressing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment