0

I have a MacRuby app, and after the app launches, I would like to launch a second process using an NSTask. The second process is a Ruby script bundled with the app. I would like to launch it using the MacRuby macruby interpreter that gets compiled into the app bundle. How can I do that?

dan
  • 43,914
  • 47
  • 153
  • 254

2 Answers2

1

First, remove the .rb extension from the ruby script, otherwise if you compile the macruby project using macruby_deploy, it will be compiled to rbo file. The script file should have this as its first line:

#!/usr/bin/env ruby

Make sure the script will be copied to Resources folder.

Then create and call a NSTask:

path = NSBundle.mainBundle.pathForResource('test', ofType:nil)
task = NSTask.alloc.init
task.setLaunchPath(path)

task.launch
James Chen
  • 10,794
  • 1
  • 41
  • 38
0

Well, have you tried just calling NSTask?

NSTask.launchedTaskWithLaunchPath('script.rb', nil)

Then click around in Xcode to make sure that script.rb is in place during execution.

nes1983
  • 15,209
  • 4
  • 44
  • 64