Skip to content

Instantly share code, notes, and snippets.

@havenwood
Created September 5, 2012 21:53
Show Gist options
  • Select an option

  • Save havenwood/3645626 to your computer and use it in GitHub Desktop.

Select an option

Save havenwood/3645626 to your computer and use it in GitHub Desktop.

Revisions

  1. havenwood revised this gist Sep 7, 2012. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions mac-app.rb
    Original file line number Diff line number Diff line change
    @@ -44,6 +44,12 @@ def create_files

    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'
  2. havenwood revised this gist Sep 7, 2012. 1 changed file with 46 additions and 4 deletions.
    50 changes: 46 additions & 4 deletions mac-app.rb
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    require 'builder'

    module MacApp
    class << self
    def new
    @@ -21,12 +23,12 @@ def ask_name

    def ask_file_extension
    print 'File Extension: '
    @ext = gets.chomp.delete('.').downcase
    @file_extension = gets.chomp.delete('.').downcase
    end

    def ask_language
    print 'Language: '
    @lang = gets.chomp.downcase
    @language = gets.chomp.downcase
    end

    def create_directories
    @@ -37,8 +39,48 @@ def create_directories
    end

    def create_files
    File.open "#@name/Contents/Info.plist", 'w'
    File.open "#@name/Contents/MacOS/app.#@ext", 'w'
    File.open "#@name/Contents/Info.plist", 'w' do |file|
    xml = Builder::XmlMarkup.new indent: 2

    xml.instruct! :xml, encoding: 'utf-8'

    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
  3. havenwood revised this gist Sep 7, 2012. 1 changed file with 29 additions and 10 deletions.
    39 changes: 29 additions & 10 deletions mac-app.rb
    Original file line number Diff line number Diff line change
    @@ -1,26 +1,45 @@
    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: '
    @ext = gets.chomp.delete('.').downcase
    end

    def ask_language
    print 'Language: '
    @lang = gets.chomp.downcase
    end

    def create_directories
    Dir.mkdir @name
    Dir.chdir @name
    Dir.mkdir 'Contents'
    Dir.chdir 'Contents'
    File.open 'Info.plist', 'w'
    Dir.mkdir 'MacOS'
    File.open "MacOS/app.#{@ext}", 'w'
    Dir.mkdir 'Resources'
    File.open "Resources/#{@name}.icns", 'w'

    system "open ../../#{@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'
    File.open "#@name/Contents/MacOS/app.#@ext", 'w'
    File.open "#@name/Contents/Resources/#@name.icns", 'w'
    end
    end
    end
  4. havenwood revised this gist Sep 5, 2012. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions mac-app.rb
    Original file line number Diff line number Diff line change
    @@ -10,8 +10,8 @@ def new
    print 'Language: '
    @lang = gets.chomp.downcase

    Dir.mkdir "#{@name}"
    Dir.chdir "#{@name}"
    Dir.mkdir @name
    Dir.chdir @name
    Dir.mkdir 'Contents'
    Dir.chdir 'Contents'
    File.open 'Info.plist', 'w'
  5. havenwood created this gist Sep 5, 2012.
    28 changes: 28 additions & 0 deletions mac-app.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    module MacApp
    class << self
    def new
    print 'App Name: '
    @name = gets.chomp.split.map(&:capitalize).join << '.app'

    print 'File Extension: '
    @ext = gets.chomp.delete('.').downcase

    print 'Language: '
    @lang = gets.chomp.downcase

    Dir.mkdir "#{@name}"
    Dir.chdir "#{@name}"
    Dir.mkdir 'Contents'
    Dir.chdir 'Contents'
    File.open 'Info.plist', 'w'
    Dir.mkdir 'MacOS'
    File.open "MacOS/app.#{@ext}", 'w'
    Dir.mkdir 'Resources'
    File.open "Resources/#{@name}.icns", 'w'

    system "open ../../#{@name}"
    end
    end
    end

    MacApp.new