Created
November 27, 2018 02:31
-
-
Save blacktm/67933ad4105e2a448d3dddc9a8e7744a to your computer and use it in GitHub Desktop.
Create macOS app bundle from an executable file
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
# Run this script using `ruby package.rb` with an executable named `app` | |
# in a `build/` directory. | |
# Build an app bundle for macOS | |
def build_macos_package | |
require 'fileutils' | |
info_plist = %( | |
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>CFBundleExecutable</key> | |
<string>app</string> | |
<key>CFBundleIconFile</key> | |
<string>app.icns</string> | |
<key>CFBundleInfoDictionaryVersion</key> | |
<string>6.0</string> | |
<key>CFBundlePackageType</key> | |
<string>APPL</string> | |
<key>CFBundleVersion</key> | |
<string>1</string> | |
<key>NSHighResolutionCapable</key> | |
<string>True</string> | |
</dict> | |
</plist> | |
) | |
# Create directories | |
FileUtils.mkpath 'build/App.app/Contents/MacOS' | |
FileUtils.mkpath 'build/App.app/Contents/Resources' | |
# Create Info.plist and copy over assets | |
File.open('build/App.app/Contents/Info.plist', 'w') { |f| f.write(info_plist) } | |
FileUtils.cp 'build/app', 'build/App.app/Contents/MacOS/' | |
# Success | |
puts 'App written to `build/App.app`.' | |
end | |
build_macos_package |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment