Henry F
Henry F

Reputation: 4980

Open External File With Ruby

I'm trying to learn Ruby, and so far I've been writing my code in text edit, saving it as a .rb file and launching it from the terminal. My main goal right now is to figure out how to open external applications, and tell them to do stuff. I'm on Mac OS X and have always used AppleScript to accomplish this. However, I have no idea how to do the same stuff in Ruby. Starting with a file, how would I go about doing this?

I've tried:

module test
    system('start John/Applications/TextEdit.app"')
end

I get the error:

test.rb:1: class/module name must be CONSTANT

I'm saving it as an rb and launching it from terminal, but that didn't work. Does anyone know how to open an external application in Ruby?

Also, once the program is open, how would I go about closing it after x amount of time?

Upvotes: 0

Views: 488

Answers (1)

Jikku Jose
Jikku Jose

Reputation: 18804

To start an external application in OSX using terminal:

$ open -a ApplicationName

To execute a terminal command via a Ruby script:

system("open -a ApplicationName")

Upvotes: 3

Related Questions