2

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?

sawa
  • 165,429
  • 45
  • 277
  • 381
  • There are quite a few steps in creating a macruby app. I put a link to them in my answer. Does that seem helpful? – vlasits Apr 12 '13 at 02:04
  • 1
    Thanks. It looks like someone deleted the part where I said I already reviewed the available tutorials. I was able to get through them, but I don't need a timer or an app that shows me how to say "Button Clicked!", etc. I guess it can be as simple as I want. I just want to be able to have the program "Run" without them having to go to Cmd Line and tell it to run. – jmitchell1009 Apr 12 '13 at 09:36
  • Ah... it will probably be hard for people to get motivated to write another (probably lengthy) version of those tutorials that is targeted just for your problem. You may want to start using the process described in the tutorials, wait until you have a **specific** problem with a step in the tutorial and then ask a more specified question. – vlasits Apr 12 '13 at 17:24

3 Answers3

3

One good way to do it:

http://macruby.org/

Sample application:

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

vlasits
  • 2,215
  • 1
  • 15
  • 27
2

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.

Chuck
  • 234,037
  • 30
  • 302
  • 389
  • I have tried Platypus, however it won't read all of my Ruby code, giving me errors where they don't exist when I run from the Command Line. FYI - the code above is not what I really need, but a basic concept. The actual code is hundreds of lines. – jmitchell1009 Apr 28 '13 at 16:59
1

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.

user2276204
  • 257
  • 1
  • 3
  • 9
  • Yes please. I will investigate on my own, however any steps to help make it easier to understand would be helpful. – jmitchell1009 Apr 28 '13 at 16:58
  • Ok. I have done this and get an error in my code. It won't read array_2.gsub(/ Ws /, ", west side").gsub(/ Es /, ", east side"), citing the 2nd ".gsub" as the line in question, with the error "sytax error, unexpected ".", expecting kEND. I get this using Platypus as well, however can run from the Command Line with no problems. Does it not recognize my current version of Ruby? Using 1.9.3 from the Command Line. I have an older version on my computer as well if that information helps. – jmitchell1009 May 01 '13 at 02:04
  • @jmitchell1009 the shell script is literally just running it as if it were on the command line. Are you using the version of ruby packaged with OS X or did you install something else? You can run `which ruby` to see which version you're calling from the command line. – user2276204 May 01 '13 at 18:15
  • Let me elaborate a bit. First I wrote a .rb file that opens a txt file, reads the data on each line, changes the data as per the code, and saves a new file. When I run "ruby filename.rb" in command line, the code runs and I have a new file. Everything works. When I build the app using your steps: 1st I added "Run Shell Script"(I used bin/bash and pass input to stdin). I typed "ruby /Users/jmitchell/Desktop/filename.rb". When I tried to run I got an notice saying I needed to add the "Get Specified Finder Items", which I did. I clicked run and got the sytax error outlined above. – jmitchell1009 May 01 '13 at 18:39
  • @jmitchell1009 It could have something to do with the path you run it from. That's the only thing I could think of from what you've said, could you share the code? – user2276204 May 02 '13 at 00:41
  • I accepted your answer as I like the look and feel of Automator the best so far, between Automator, Xcode, and Platypus, however I still can't get it to work, so I made a new question here, with code and more details. Thanks. http://stackoverflow.com/questions/16344287/mac-automator-os-10-7-not-reading-ruby-1-9-3 – jmitchell1009 May 02 '13 at 17:38
  • @jmitchell1009 As mentioned in the other question, it is likely the newline after the second ".gsub" that's doing it, although I'm not quite sure why it would be different for different places. – user2276204 May 02 '13 at 19:03