# Using StandardAdditions.osax with appscript

**URL:** <https://www.ruby-forum.com/t/using-standardadditions-osax-with-appscript/112381>\
**Category:** Ruby\
**Created:** [August 18, 2007, 3:13am UTC](https://www.ruby-forum.com/t/using-standardadditions-osax-with-appscript/112381 "2007-08-18T03:13:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Morton\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/dfb087/32.png) [@Morton\_G](https://www.ruby-forum.com/u/Morton_G)\
**Post date:** [August 18, 2007, 3:13am UTC](https://www.ruby-forum.com/t/using-standardadditions-osax-with-appscript/112381/1 "2007-08-18T03:13:06Z")

</div>

Can anybody tell me how to execute a command (e.g., beep) implemented  
in /System/Library/ScriptingAdditions/StandardAdditions.osax from a  
Ruby script using the appscript library? What I thought might work was

`
#! /usr/bin/env ruby -w
require “appscript”
include Appscript
std_adds =
app(’/System/Library/ScriptingAdditions/StandardAdditions.osax’)
std_adds.beep(3)
`

but it produced the following

/usr/lib/ruby/site\_ruby/1.8/\_aem/mactypes.rb:92: warning: method redefined; discarding old desc AE::MacOSError: #

method launch\_application in connect.rb at line 76  
method local\_app in connect.rb at line 76  
method by\_path in aem.rb at line 116  
method send in appscript.rb at line 47  
method connect in appscript.rb at line 47  
method reference\_by\_name in appscript.rb at line 82  
method method\_missing in appscript.rb at line 522  
at top level in untitled document at line 8

Program exited.

Regards, Morton

---

<div class="post-metadata">

**Author:** ![Morton\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/dfb087/32.png) [@Morton\_G](https://www.ruby-forum.com/u/Morton_G)\
**Post date:** [August 18, 2007, 4:23am UTC](https://www.ruby-forum.com/t/using-standardadditions-osax-with-appscript/112381/2 "2007-08-18T04:23:46Z")

</div>

a workaround for this:

1. Execute applescript in shell command
2. Execute shell command in ruby

Examle:

```auto
Applescript:

tell application "Finder"
  delete file "Untitled.rtf"
  delete file "untitled2.rtf"
end tell

Ruby:
command = "osascript -e 'tell application "Finder" to delete file 
"untitled.rtf"' -e 'tell application "Finder" to delete file 
"untitled2.rtf"'"
system (command)
```

That will execute the string in command inthe shell.  
I couldn’t test it but hope it works.

---

<div class="post-metadata">

**Author:** ![Morton\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/dfb087/32.png) [@Morton\_G](https://www.ruby-forum.com/u/Morton_G)\
**Post date:** [August 18, 2007, 8:05am UTC](https://www.ruby-forum.com/t/using-standardadditions-osax-with-appscript/112381/3 "2007-08-18T08:05:23Z")

</div>

On Aug 17, 2007, at 10:23 PM, Vasil V. wrote:

> delete file “Untitled.rtf”  
> That will execute the string in command inthe shell.  
> I couldn’t test it but hope it works.

Yeah, I could do that. But it would kind of spoil the fun. As I see  
it, the whole idea of the appscript library is make the sort of thing  
you suggest unnecessary. The appscript library works pretty good for  
replacing the AppleScript I tend to use. I much prefer writing

`
require "appscript"
include Appscript
finder = app(‘Finder’)
finder.count(finder.desktop, :each => :file) # => 2
finder.disks[its.local_volume.eq(true)].get.size # => 3
`

to

tell app "Finder" set onDesk to count desktop's files set drives to (disks whose local volume is true) set drives to drives's length {onDesk, drives} end tell

I just wish I knew how to access the the standard scripting additions.

Regards, Morton

---

<div class="post-metadata">

**Author:** ![Morton\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/dfb087/32.png) [@Morton\_G](https://www.ruby-forum.com/u/Morton_G)\
**Post date:** [August 18, 2007, 12:11pm UTC](https://www.ruby-forum.com/t/using-standardadditions-osax-with-appscript/112381/4 "2007-08-18T12:11:41Z")

</div>

On 18 Aug, 02:11, Morton G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Can anybody tell me how to execute a command (e.g., beep) implemented  
> in /System/Library/ScriptingAdditions/StandardAdditions.osax from a  
> Ruby script using the appscript library?

Use the osax module bundled with appscript, e.g.:

require ‘osax’

StdAdditions = OSAX.osax

StdAdditions.beep

See the appscript documentation for more info.

HTH

has

---

<div class="post-metadata">

**Author:** ![Morton\_G](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/dfb087/32.png) [@Morton\_G](https://www.ruby-forum.com/u/Morton_G)\
**Post date:** [August 18, 2007, 7:53pm UTC](https://www.ruby-forum.com/t/using-standardadditions-osax-with-appscript/112381/5 "2007-08-18T19:53:45Z")

</div>

On Aug 18, 2007, at 6:10 AM, has wrote:

> StdAdditions.beep
> 
> See the appscript documentation for more info.
> 
> HTH

It does indeed help. Exactly the info I was looking for. Thanks a lot.

Regards, Morton
