Ruby OSA "AppleScript" for the Macintosh

Are you a Macintosh scripter who hoped that the title of this message
was an announcement? If so, you're not alone! (I mean, I know that at
least *I* want this.)

For those who don't know: Apple's scripting architecture used by
AppleScript is actually sort of like .NET - there's an "Open Scripting
Architecture" at the core that theoretically allows you do use
different scripting languages (such as "French Applescript" or
JavaScript[1]).

If someone writes an OSA plugin for a particular language, all the
automation capabilities exposed to "AppleScript" by all the various
applications under Mac OS are available to that new language. The
"Script Editor" application that comes with Mac OS supports[2] the new
language.

I'm sure I'll never finish it, but the point of this post is to find
out if anyone smarter than me knows about Ruby and OSA, and knows what
it would take to at least START a Ruby OSA.

Because, as you know, Ruby rocks. AppleScript "rocks" insofar as so
many apps are AppleScriptable, but it's a terrible language. I mean,
why does this work:
  copy (get songling's location) to trackpath
  tell application "Finder" to duplicate trackpath to destination
but this doesn't:
  tell application "Finder" to duplicate (get songling's location) to
destination
?!

I'd much rather write:
  Applications[ "Finder" ].duplicate( songling.location, destination )
or perhaps
  songling.location.duplicate( :to => destination )

So, anyone got any idea where to start on a project like this? Or have
any reasons why it's totally useless to attempt?

[1] http://www.latenightsw.com/freeware/JavaScriptOSA/index.html
[2] Syntax coloring doesn't seem to come for free, however.

I think you left your google at home <g>: http://www.fobj.com/rubyaeosa/

···

On Sep 3, 2006, at 11:23 PM, Phrogz wrote:

I'm sure I'll never finish it, but the point of this post is to find
out if anyone smarter than me knows about Ruby and OSA, and knows what
it would take to at least START a Ruby OSA.

that's easy :

--- truc.rb ------------------------------------------------------------
#!/usr/bin/env ruby

require 'osx/aeosa'

as="tell application \"Finder\"
        activate
        set my_folder to version choose folder
        set my_folder to POSIX path of my_folder
end tell
my_folder"
puts OSX.do_osascript(as).to_rbobj

···

Phrogz <gavin@refinery.com> wrote:

I'm sure I'll never finish it, but the point of this post is to find
out if anyone smarter than me knows about Ruby and OSA, and knows what
it would take to at least START a Ruby OSA.

------------------------------------------------------------------------

provided you have installed RubyAEOSA.

other solution if you don't want to install RubyAEOSA.
u'll have to files one "choose_folder.applescript" call by the other
"run_applescript.rb" :

--- choose_folder.applescript ------------------------------------------
tell application "Finder"
        activate
        set my_folder to version choose folder
        set my_folder to POSIX path of my_folder
end tell
my_folder
------------------------------------------------------------------------

--- run_applescript.rb -------------------------------------------------
#!/usr/bin/env ruby
puts r=`osascript choose_folder.applescript`.chomp
------------------------------------------------------------------------

--
une bévue

Logan Capaldo wrote:

I think you left your google at home <g>: http://www.fobj.com/rubyaeosa/

I wish that were true. I probably should have mentioned why that isn't
an aswers to the question, despite having all the right letters in the
name.

With the JavaScript OSA, you:
a) Drop a component in your Library
b) Choose JavaScript as the language in the Script Editor application
c) Write actual JavaScript code that exercises OSA to script
applications.

For example:
  with (MacOS.finder())
      files["JavaScript"].move(folders["untitled folder"], false);

  // in AppleScript, this would be expressed as
  // tell application "Finder"
  // move file "JavaScript" to folder "untitled folder" without
replacing
  // end tell

This is very different (in my mind, anyhow, and I assume everyone's)
from either:

a) Embedding AppleScript code within your desired language:
  SCRIPT = <<SCRIPT
  tell application "TextEdit"
    tell text of front document
      third paragraph
    end
  end
  SCRIPT
  puts OSX.do_osascript(SCRIPT).to_s.strip

or b) Sending raw, cryptic apple event codes around:
  app = OSX::AEDesc.application "TextEdit"
  app.ae_send ('aevt', 'odoc', OSX::AEDesc.fss ("README.en"))

Maybe this RubyAEOSA project is the start needed to move in the
direction that JavaScript OSA exists, but it's definitely not there,
and (as far as I can tell) it's not planning on heading in that
direction.