Frankly speaking, the approach I am talking about here is to create a Mac console-like application as we are not able to build a real Mac console application using RubyMotion when I post this article.
It takes only 3 steps, let’s get started.
Firstly, create a RubyMotion project using OS X template. In my example, I call it ConsoleMotion:
$ motion create --template=osx ConsoleMotion
Secondly, edit the Rakefile and add the following lines of code:
# -*- coding: utf-8 -*-$:.unshift("/Library/RubyMotion/lib")require'motion/project/template/osx'Motion::Project::App.setupdo|app|# Use `rake config' to see complete project settings.app.name='ConsoleMotion'app.info_plist['LSUIElement']=true# Add this lineend
When the LSUIElement property of your application’s info plist is set to true, your app will not appear in the Dock as the documentation says.
Thirdly, edit the app_delegate.rb and implement applicationDidFinishLaunching method as follows:
classAppDelegatedefapplicationDidFinishLaunching(notification)args=NSProcessInfo.processInfo.arguments# get the arguments passing to your console-like appstr=args||"hello world"# do whatever you want herepstrexit# exit the app when you finish your jobendend
the key point is the exit function which quits your app when jobs finish like what the normal console apps do.