Search code examples
rubyswiftxcodemacosnstask

Use non-system ruby to execute ruby scripts within macOS App


I'm building an macOS app which needs to execute a framework written in ruby. Currently with macOS High Sierra 10.13.x the system ruby version is only 2.3.3. I'm using brew / rvm (it depends) to install up to date versions.

When trying to run /usr/local/bin/ruby or ~/.rvm/rubies/ruby-2.5.0/bin/ruby with Process Xcode throws the error that Operation is not permitted.

This works fine when using /usr/bin/ruby as launchPath.

Is there a way to execute ruby from /usr/local/bin/ruby or ~/.rvm/rubies/ruby-2.5.0/bin/ruby or any other custom paths?

With the current version of macOS it is also not possible to update the symbolic link of /usr/bin/ruby to a different binary.

Here is my implementation so far:

let myScript = Bundle.main.path(forResource: "myScript", ofType: "command")

let task = Process()    
task.launchPath = "/bin/sh"
task.arguments = myScript, basePath
taks.launch()

And here is myScript content:

#!/bin/sh -l

BASE_PATH="$1"
cd "${BASE_PATH}"

/usr/local/bin/ruby my_ruby_script.rb

When I launch the task I got this message:

 /usr/local/bin/ruby: Operation not permitted

or

~/.rvm/rubies/ruby-2.5.0/bin/ruby: Operation not permitted

Hope you have a solution.


Solution

  • Due to Martin R's help I was able to solve the issue. For now I deactivated macOS sandboxing in the projects capabilities.

    Now I can use any ruby I want.

    Thank you