# Ruby OSA "AppleScript" for the Macintosh

**URL:** <https://www.ruby-forum.com/t/ruby-osa-applescript-for-the-macintosh/67455>\
**Category:** Ruby\
**Created:** [September 4, 2006, 2:44pm UTC](https://www.ruby-forum.com/t/ruby-osa-applescript-for-the-macintosh/67455 "2006-09-04T14:44:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![phrogz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2acd7d/32.png) [@phrogz](https://www.ruby-forum.com/u/phrogz)\
**Post date:** [September 4, 2006, 2:44pm UTC](https://www.ruby-forum.com/t/ruby-osa-applescript-for-the-macintosh/67455/1 "2006-09-04T14:44:06Z")

</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:  
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] [Memories of JavaScript OSA - javascript - Late Night Software Ltd.](http://www.latenightsw.com/freeware/JavaScriptOSA/index.html)  
[2] Syntax coloring doesn’t seem to come for free, however.

---

<div class="post-metadata">

**Author:** ![phrogz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2acd7d/32.png) [@phrogz](https://www.ruby-forum.com/u/phrogz)\
**Post date:** [September 4, 2006, 2:44pm UTC](https://www.ruby-forum.com/t/ruby-osa-applescript-for-the-macintosh/67455/2 "2006-09-04T14:44:07Z")

</div>

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.

I think you left your google at home : [http://www.fobj.com/rubyaeosa/](http://www.fobj.com/rubyaeosa/)

---

<div class="post-metadata">

**Author:** ![phrogz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2acd7d/32.png) [@phrogz](https://www.ruby-forum.com/u/phrogz)\
**Post date:** [September 7, 2006, 7:57pm UTC](https://www.ruby-forum.com/t/ruby-osa-applescript-for-the-macintosh/67455/3 "2006-09-07T19:57:41Z")

</div>

Phrogz [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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

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

---

<div class="post-metadata">

**Author:** ![phrogz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/2acd7d/32.png) [@phrogz](https://www.ruby-forum.com/u/phrogz)\
**Post date:** [September 7, 2006, 10:34pm UTC](https://www.ruby-forum.com/t/ruby-osa-applescript-for-the-macintosh/67455/4 "2006-09-07T22:34:04Z")

</div>

Logan C. wrote:

> I think you left your google at home : [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:  
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.
