Question

I'm a beginner at Ruby and I don't know how to do this....

Right now I have the script and it runs perfectly in terminal but I was hoping to be able to create a double clickable version of it on the desktop that would then open a window in terminal and run the script. Automator and Platypus don't work. I'm not sure what to do. Thank you in advance.

Was it helpful?

Solution

Assuming you're targeting Mac OS X (Unix) or Linux you can put this line at the top of your Ruby file to make it compatible with the Terminal:

#!/bin/ruby

Basically, this tells the shell (Terminal) to run the contents of the file with whatever executable you write after #!. In this case, you're instructing it to use the ruby executable that you use to run your code elsewhere.

To allow the Ruby script to be executed, you'll need to make it executable by running:

chmod a+x my_script.rb 

Finally, to get double clicking support, you might have to replace the .rb extension with .sh so the operating system recognizes it as a shell script and not a Ruby file.

You might also consider a GUI of some sort. Shoes is a great way to create nice user interfaces, and it's really easy to use. It also allows you to generate executable files for Windows, OS X, and Linux if I remember correctly.

Here's an example, which creates a basic, clickable button:

Shoes.app do
  @button = button "Click Me"

  @button.click do
    puts "Clicked!"
  end
end

OTHER TIPS

Well you can write a quick shell script that's basically running your ruby script and make this shell script executable. See the link bellow:

How to run a shell script in OS X by double-clicking?

The content of your shell script can be as simple as that:

ruby /yourpath/yourscript.rb
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top