Mac Automator (OS 10.7) not reading Ruby 1.9.3? -
i have ruby code in .rb file trying run automator opposed command line. here sample of code (filename "filelines_revise.rb"):
lines = io.readlines('filelines_before_cap.txt').map |line| array = line.split.each { |i| i.capitalize! } if array.include?("ws") array.delete("ws") array[-1,0] = "ws" end if array.include?("es") array.delete("es") array[-1,0] = "es" end array_2 = array.join(" ") array_2.gsub(/ ws /, ", west side") .gsub(/ es /, ", east side") end file.open('filelines_after_cap.txt', 'w') |file| file.puts lines end
when run code using command line command "ruby /desktop/filelines_revise/filelines_revise.rb" , code runs fine. finds original .txt file, reads each line, changes file code dictates, creates new file revised lines.
when try put automator either workflow or app, put run shell script flow, using /bin/bash pass input: stdin, command "ruby /desktop/filelines_revise/filelines_revise.rb". when go run script error reading:
desktop/filelines_revise/filelines_revise.rb:18 syntax error, unexpected '.', expecting kend
line 18 2nd .gsub ".gsub(/ es /, ", east side")" listed in code above.
is possible automator isn't using ruby 1.9.3 command line does? perhaps should going differently? in advance.
how ruby version determined? i'm betting automator knows nothing of it. running built-in ruby 1.8.7. can check examining ruby_version
in course of script.
the issue shell environment double-clickables (like automator) not same shell environment terminal (which uses .bash_profile
).
bbedit had same problem until version 10.5, way. takes special effort double-clickable app pick terminal shell environment, , applications not make effort.
edit: took @ automator , discovered if run shell script enter literally run shell script action, have switch popup /usr/bin/ruby
. of course ruby not ruby @ /usr/bin/ruby
. /usr/bin/ruby
1.8.7; ruby not want use. , can't provide shebang line!
so set popup /bin/bash/
, ran script:
/usr/bin/env ruby /users/matt/desktop/test.rb
where test.rb
reads:
puts ruby_version
running within automator, still got "1.8.7". tried application , service; same result. don't think can ever automator use built-in ruby 1.8.7 without pointing directly ruby want; doesn't pick shell way terminal does.
Comments
Post a Comment