-
-
Save TylerBrock/3708768 to your computer and use it in GitHub Desktop.
Create an OS X .app Executable With Your Choice Of Language For Script
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 'builder' | |
module MacApp | |
class << self | |
def new | |
ask_name | |
ask_file_extension | |
ask_language | |
create_directories | |
create_files | |
end | |
def run | |
system "open #@name" | |
end | |
private | |
def ask_name | |
print 'App Name: ' | |
@name = gets.chomp.split.map(&:capitalize).join << '.app' | |
end | |
def ask_file_extension | |
print 'File Extension: ' | |
@file_extension = gets.chomp.delete('.').downcase | |
end | |
def ask_language | |
print 'Language: ' | |
@language = gets.chomp.downcase | |
end | |
def create_directories | |
Dir.mkdir @name | |
Dir.mkdir "#@name/Contents" | |
Dir.mkdir "#@name/Contents/MacOS" | |
Dir.mkdir "#@name/Contents/Resources" | |
end | |
def create_files | |
File.open "#@name/Contents/Info.plist", 'w' do |file| | |
xml = Builder::XmlMarkup.new indent: 2 | |
xml.instruct! :xml, encoding: 'utf-8' | |
xml.declare! :DOCTYPE, | |
:plist, | |
:PUBLIC, | |
'-//Apple//DTD PLIST 1.0//EN', | |
'http://www.apple.com/DTDs/PropertyList-1.0.dtd' | |
xml.plist version: '1.0' do |plist| | |
plist.dict do |dict| | |
dict.key 'CFBundlePackageType' | |
dict.string 'APPL' | |
dict.key 'CFBundleInfoDictionaryVersion' | |
dict.string '6.0' | |
dict.key 'CFBundleIconFile' | |
dict.string "#@name.icns" | |
dict.key 'CFBundleName' | |
dict.string "#@name by Orchid Technologies" | |
dict.key 'CFBundleExecutable' | |
dict.string "app.#@file_extension" | |
dict.key 'CFBundleIdentifier' | |
dict.string @name | |
dict.key 'CFBundleVersion' | |
dict.string '0.1' | |
dict.key 'NSHumanReadableCopyright' | |
dict.string 'Author Copyright 2012' | |
end | |
end | |
file << xml | |
end | |
File.open "#@name/Contents/MacOS/app.#@file_extension", 'w' do |file| | |
file << "#!/usr/bin/env #@language\n# Code goes here..." | |
end | |
File.chmod 0755, "#@name/Contents/MacOS/app.#@file_extension" | |
File.open "#@name/Contents/Resources/#@name.icns", 'w' | |
end | |
end | |
end | |
MacApp.new |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment