# Ruby OSA "AppleScript" for the Macintosh

**URL:** <https://rubytalk.org/t/ruby-osa-applescript-for-the-macintosh/30622>\
**Category:** ruby-talk\
**Created:** [4 September 2006 03:23 UTC](https://rubytalk.org/t/ruby-osa-applescript-for-the-macintosh/30622 "2006-09-04T03:23:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gavin\_Kistner2](https://avatars.discourse-cdn.com/v4/letter/g/b9e5f3/32.png) [@Gavin\_Kistner2](https://rubytalk.org/u/Gavin_Kistner2)\
**Post date:** [4 September 2006 03:23 UTC](https://rubytalk.org/t/ruby-osa-applescript-for-the-macintosh/30622/1 "2006-09-04T03:23:44Z")

</div>

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:  
&nbsp;&nbsp;copy (get songling's location) to trackpath  
&nbsp;&nbsp;tell application "Finder" to duplicate trackpath to destination  
but this doesn't:  
&nbsp;&nbsp;tell application "Finder" to duplicate (get songling's location) to  
destination  
?!

I'd much rather write:  
&nbsp;&nbsp;Applications["Finder"].duplicate( songling.location, destination )  
or perhaps  
&nbsp;&nbsp;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](http://www.latenightsw.com/freeware/JavaScriptOSA/index.html)  
[2] Syntax coloring doesn't seem to come for free, however.

---

<div class="post-metadata">

**Author:** ![Logan\_Capaldo](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@Logan\_Capaldo](https://rubytalk.org/u/Logan_Capaldo)\
**Post date:** [4 September 2006 03:33 UTC](https://rubytalk.org/t/ruby-osa-applescript-for-the-macintosh/30622/2 "2006-09-04T03:33:45Z")

</div>

I think you left your google at home \<g\>: [http://www.fobj.com/rubyaeosa/](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.

---

<div class="post-metadata">

**Author:** ![Pere\_Noel1](https://avatars.discourse-cdn.com/v4/letter/p/d6d6ee/32.png) [@Pere\_Noel1](https://rubytalk.org/u/Pere_Noel1)\
**Post date:** [7 September 2006 17:50 UTC](https://rubytalk.org/t/ruby-osa-applescript-for-the-macintosh/30622/3 "2006-09-07T17:50:24Z")

</div>

that's easy :

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

require 'osx/aeosa'

as="tell application \"Finder\"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;activate  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set my\_folder to version choose folder  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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"  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;activate  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;set my\_folder to version choose folder  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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

---

<div class="post-metadata">

**Author:** ![Gavin\_Kistner2](https://avatars.discourse-cdn.com/v4/letter/g/b9e5f3/32.png) [@Gavin\_Kistner2](https://rubytalk.org/u/Gavin_Kistner2)\
**Post date:** [7 September 2006 20:30 UTC](https://rubytalk.org/t/ruby-osa-applescript-for-the-macintosh/30622/4 "2006-09-07T20:30:16Z")

</div>

Logan Capaldo wrote:

> I think you left your google at home \<g\>: [http://www.fobj.com/rubyaeosa/](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:  
&nbsp;&nbsp;with (MacOS.finder())  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;files["JavaScript"].move(folders["untitled folder"], false);

&nbsp;&nbsp;// in AppleScript, this would be expressed as  
&nbsp;&nbsp;// tell application "Finder"  
&nbsp;&nbsp;// move file "JavaScript" to folder "untitled folder" without  
replacing  
&nbsp;&nbsp;// 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:  
&nbsp;&nbsp;SCRIPT = \<\<SCRIPT  
&nbsp;&nbsp;tell application "TextEdit"  
&nbsp;&nbsp;&nbsp;&nbsp;tell text of front document  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;third paragraph  
&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;end  
&nbsp;&nbsp;SCRIPT  
&nbsp;&nbsp;puts OSX.do\_osascript(SCRIPT).to\_s.strip

or b) Sending raw, cryptic apple event codes around:  
&nbsp;&nbsp;app = OSX::AEDesc.application "TextEdit"  
&nbsp;&nbsp;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.
