0

I want to write a simple script that will check to see if a program is open every hour using the whenever gem. If that application is not open I want it to start up the application. I can't find out how to launch an application with Ruby. Pardon the ignorance. I am new.

Scott
  • 471
  • 3
  • 9
  • 19
  • whenever just makes cronjobs. You need a script to do all the things you say, first. Scheduling it to run every hour is step 2. Try to make the script to check if an application is open, and running it "normally" first. – Martin Tournoij Dec 13 '14 at 06:04

2 Answers2

1

Run an application in various ways:

Kernel#system runs my_program in a subshell and returns true if the subshell exits successfully, false otherwise.

system("my_program")

Kernel#exec replaces the currently executing process with my_program.

exec("my_program")

%x() will run the program and return the output.

%x(my_program)

Fred
  • 8,582
  • 1
  • 21
  • 27
0

You can use the Kernal#system method like this:

system 'open -n /Applications/Appname.app'

With #system you'll get a return value of true or false, enabling you to do some flow control incase there's an issue (i.e. maybe the app doesn't exist in the system)

Anthony
  • 15,435
  • 4
  • 39
  • 69