Last active
March 27, 2024 15:21
-
-
Save Draknek/3ce889860cea4f59838386a79cc11a85 to your computer and use it in GitHub Desktop.
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.
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 python3 | |
import os | |
import sys | |
import time | |
import zipfile | |
startingdir = os.getcwd() | |
if (len(sys.argv) == 1): | |
print("Usage: " + os.path.basename(sys.argv[0]) + " path/to/application.app [path/to/output.zip]") | |
sys.exit() | |
if (len(sys.argv) > 3): | |
print("Wrong number of arguments - needs 1 or 2") | |
sys.exit(1) | |
appdir = sys.argv[1] | |
if (appdir[-5:] == ".app/"): | |
appdir = appdir[0:-1] | |
if (appdir[-4:] != ".app"): | |
print("Error: " + appdir + " is not a .app file.") | |
sys.exit(2) | |
dir = os.path.dirname(appdir) | |
if (not os.path.exists(appdir)): | |
print("Error: " + appdir + " does not exist.") | |
sys.exit(3) | |
os.chdir(dir) | |
appdir = os.path.basename(appdir) | |
zipname = appdir[0:-4] + ".zip" | |
if (len(sys.argv) == 3): | |
zipname = sys.argv[2] | |
zippath = os.path.join(startingdir, zipname) | |
else: | |
zippath = zipname | |
searchname = os.path.join(appdir, "Contents", "MacOS") | |
zip = zipfile.ZipFile(zippath, '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, 'rb') | |
bytes = f.read() | |
f.close() | |
info = zipfile.ZipInfo(filename) | |
info.date_time = time.localtime() | |
info.create_system = 3; # Pretend file is from unix | |
info.external_attr = 0o100755 << 16 # Set file permissions | |
zip.writestr(info, bytes, zipfile.ZIP_DEFLATED) | |
else: | |
zip.write(filename) | |
zip.close() | |
print("Created " + zipname) |
Updated to python3, and fixed some issues (previously it seemed to be working on Windows from WSL but not otherwise)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Could you tell me how to keep the soft connection when decompressing?