Skip to content

Instantly share code, notes, and snippets.

@blacktm
Created November 13, 2013 04:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blacktm/7443665 to your computer and use it in GitHub Desktop.
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.
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