^ home

Ruby to AppleScript

A simple program that takes a ruby program (such as test.rb) and converts it to an AppleScript function that does the same thing as the ruby program. (For all of you who like writing programs in Ruby better than writing programs in AppleScript.)

The program assumes that the ruby script takes a single argument, but it could easily be converted to work with more arguments:

file = ARGV[0]

text = ''
File.open(file + ".rb") {|f| text = f.read}
text.gsub!("\\", "\\\\\\")
text.gsub!('"', '\\"')

puts "on #{file}(arg)"
puts "\tset cmd to \"#{text}\""
puts "\tset res to (do shell script \"/usr/bin/ruby -e \" & quoted form of cmd & \" \" & quoted form of arg)"
puts "\treturn res"
puts "end"


home ^

© 2012, Niklas Frykholm, administrator@frykholm.se