Mac Automator (OS 10.7) not reading Ruby 1.9.3?

前端 未结 1 1405
青春惊慌失措
青春惊慌失措 2021-01-26 09:48

I have some Ruby code in a .rb file that I am trying to run with Automator as opposed to the Command Line. Here is a sample of the code (filename is \"filelines_revise.rb\"):

相关标签:
1条回答
  • 2021-01-26 10:01

    How is your Ruby version determined? I'm betting that Automator knows nothing of it. It is probably running the built-in Ruby 1.8.7. You can easily check that by examining RUBY_VERSION in the course of your script.

    The issue would then be that the shell environment for double-clickables (like Automator) is not the same as the shell environment for the Terminal (which uses your .bash_profile).

    BBEdit had the same problem until version 10.5, by the way. It takes a special effort for a double-clickable app to pick up the Terminal shell environment, and most applications do not make that effort.

    EDIT: I took a look at Automator and discovered that if you run a shell script that you enter literally with the Run Shell Script action, you have to switch the popup to /usr/bin/ruby. But of course my ruby is not the ruby at /usr/bin/ruby. /usr/bin/ruby is 1.8.7; that is the ruby I do not want to use. And you can't provide a shebang line!

    So I set the popup to /bin/bash/ and ran this script:

    /usr/bin/env ruby /Users/matt/Desktop/test.rb
    

    Where test.rb reads:

    puts RUBY_VERSION
    

    Running that within Automator, I still got "1.8.7". I also tried it as an application and as a service; same result. So I don't think you can ever get Automator to use anything but the built-in ruby 1.8.7 without pointing directly to the ruby that you want; it doesn't pick it up from the shell the way Terminal does.

    0 讨论(0)
提交回复
热议问题