Women in Technology

Hear us Roar



Article:
  Replacing AppleScript with Ruby
Subject:   passing requests from applescripts to rb-appscripts
Date:   2008-04-08 10:56:02
From:   gauvins
Thanks for an excellent post. I've been able to run your example without problem, from the Terminal.


I am unable, however, to figure how an applescript can call an rb-appscript.


Terminal: ruby test2.rb /Users/gauvins/Desktop/test.txt (does work)


AppleScript:


set the_params to /Users/gauvins/Desktop/test.txt
do shell script ruby test2.rb & the_params


does not work. Including variants


Any idea?


(I am not a developper at all. Just a poor soul trying to automate a very tedious task :)

Full Threads Oldest First

Showing messages 1 through 2 of 2.

  • Matt Neuburg photo passing requests from applescripts to rb-appscripts
    2008-04-08 11:21:34  Matt Neuburg | O'Reilly AuthorO'Reilly Blogger [View]

    Hi, gauvins -

    I'm not sure why you'd want to do this; the whole point of my article here is that you can just start in Ruby and stay in Ruby, and never use any AppleScript code at all. However, my book explains about calling Perl, Ruby, etc. from AppleScript and vice versa. Here is a simple example.

    Ruby file /Users/mattneub/Desktop/test.rb:

    puts $*[0].reverse


    AppleScript code:

    set f to "/Users/mattneub/Desktop/test.rb"
    set s to "ruby " & quoted form of f & space & quoted form of "Hello, World!"
    do shell script s -- result: "!dlroW ,olleH"


    Here is another example.

    Ruby file /Users/mattneub/Desktop/test.rb:

    require "appscript"
    include Appscript
    puts app('Finder').name.get


    AppleScript code:

    set f to "/Users/mattneub/Desktop/test.rb"
    set s to "ruby " & quoted form of f
    do shell script s -- result: "Finder"
    That should get you started.

    • passing requests from applescripts to rb-appscripts
      2008-04-08 16:23:08  gauvins [View]

      Thanks Matt for the (quick) follow-up

      first snippets work well. Second do not. I get the following error message :

      /Users/gauvins/Desktop/test.rb:1:in `require': no such file to load -- appscript (LoadError)
      from /Users/gauvins/Desktop/test.rb:1

      ---

      I stumbled upon your post searching for a way to do exactly what you did in your example (count instances of words in a list). The (few) applescripts examples I could locate seemed very inefficient. An Applescript based app chokes on the large file I used to test the procedure (close to 1G ...).

      I understand that Rb-script could be immensely superior, but I would rather try to use your code as some kind of external function, for the moment at least. Maybe this summer I can find the time to rewrite.