Created
November 13, 2013 04:24
-
-
Save blacktm/7443665 to your computer and use it in GitHub Desktop.
A little Ruby script to package another script as an OS X Application.
This file contains hidden or 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
require 'fileutils' | |
if Dir.exists? "App.app" | |
puts "Nope" | |
exit | |
end | |
FileUtils.mkpath "App.app/Contents/MacOS" | |
FileUtils.mkpath "App.app/Contents/Resources" | |
info_plist = %Q[ | |
<?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>run.sh</string> | |
<key>CFBundleIconFile</key> | |
<string>app.icns</string> | |
<key>CFBundleInfoDictionaryVersion</key> | |
<string>1.0</string> | |
<key>CFBundlePackageType</key> | |
<string>APPL</string> | |
<key>CFBundleSignature</key> | |
<string>????</string> | |
<key>CFBundleVersion</key> | |
<string>1.0</string> | |
</dict> | |
</plist> | |
] | |
File.open("App.app/Contents/Info.plist", 'w') { |f| f.write(info_plist) } | |
run_sh = %Q[#!/bin/bash | |
say hi | |
# Add RVM to $PATH | |
[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" | |
# Add rbenv to $PATH | |
export PATH="$HOME/.rbenv/bin:$PATH" | |
# Change working path | |
cd "$(dirname "$0")/../Resources/" | |
# Start app | |
ruby app.rb | |
] | |
File.open("App.app/Contents/MacOS/run.sh", 'w') { |f| f.write(run_sh) } | |
File.chmod(0777, "App.app/Contents/MacOS/run.sh") | |
# Copy all files to Resources | |
FileUtils.cp_r(Dir["app/*"], "App.app/Contents/Resources") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment