jmitchell1009
jmitchell1009

Reputation: 37

Change Ruby program into simple Desktop Mac App

I have a program that reads the data in a file, changes certain elements, and creates a new file. The code looks like this:

lines = IO.readlines('single_before_CAP.txt').map do |line|
a = line.split.each { |i| i.capitalize! }
a2 = a.join(" ")
File.open('single_after_CAP.txt', 'w') do |file|
  file.puts lines
end

How can I use Xcode and MacRuby to get this program to run as a GUI app? If not Xcode and MacRuby, is there another simple task I can do to make this a standalone GUI app?

Upvotes: 2

Views: 1007

Answers (3)

user2276204
user2276204

Reputation: 257

If you just want to run a headless ruby application, you can use Automator. Simply create a new workflow, add a line to execute your application, and save it as a ".app". I can give you more specific instructions if you like.

@jmitchell1009

Specific Instructions: If you don't need to input anything to your program (like files or arguments) the simplest way would be to:

  1. Open Automater
  2. Select new "Application" (This will save your final output as a .app, you can choose another option if you want something else)
  3. Select the "Run Shell Script" action, and drag this into your workflow.
  4. Select a shell to run it in (shouldn't matter too much if you're just running a ruby application).
  5. Select where input should go (again, if you have no input, it should matter too much)
  6. Enter the command for your ruby application. Something like "ruby commandpath" etc. (without quotes of course)
  7. You may want to run it a few times to make sure it works. Once you're done, you can save the workflow and it will create a .app for you.

If you have any issues, let me know.

Upvotes: 1

Chuck
Chuck

Reputation: 237010

It sounds like what you want is basically a simple wrapper app that runs your script when double-clicked, rather than a full GUI. Platypus is the easiest way to do that. You just give it your script, set up a couple of parameters (e.g. whether your script wants a file as an argument) and it'll give you a double-clickable app that optionally includes a simple interface such as a progress bar or text output.

Upvotes: 2

vlasits
vlasits

Reputation: 2235

One good way to do it:

http://macruby.org/

Sample application:

https://github.com/MacRuby/MacRuby/wiki/Creating-a-simple-application

Upvotes: 3

Related Questions