[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Using StandardAdditions.osax with appscript

Morton Goldberg

8/18/2007 1:12:00 AM

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

<code>
#! /usr/bin/env ruby -w

require "appscript"
include Appscript

std_adds =
app('/System/Library/ScriptingAdditions/StandardAdditions.osax')
std_adds.beep(3)
</code>

but it produced the following

<result>
/usr/lib/ruby/site_ruby/1.8/_aem/mactypes.rb:92: warning: method
redefined; discarding old desc
AE::MacOSError: #<AE::MacOSError -10827>

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.
</result>

Regards, Morton

4 Answers

Vasil Vangelovski

8/18/2007 2:24:00 AM

0

a workaround for this:
1. Execute applescript in shell command
2. Execute shell command in ruby

Examle:

[code]
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)
[/code]

That will execute the string in command inthe shell.
I couldn't test it but hope it works.
--
Posted via http://www.ruby-....

Morton Goldberg

8/18/2007 6:04:00 AM

0

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

> a workaround for this:
> 1. Execute applescript in shell command
> 2. Execute shell command in ruby
>
> Examle:
>
> [code]
> 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)
> [/code]
>
> 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

<code>
require "appscript"
include Appscript

finder = app('Finder')
finder.count(finder.desktop, :each => :file) # => 2
finder.disks[its.local_volume.eq(true)].get.size # => 3
</code>

to

</code>
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
</code>

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

Regards, Morton

hengist podd

8/18/2007 10:07:00 AM

0

On 18 Aug, 02:11, Morton Goldberg <m_goldb...@ameritech.net> 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
--
http://appscript.sourc...
http://rb-appscript.rub...

Morton Goldberg

8/18/2007 5:52:00 PM

0

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

> On 18 Aug, 02:11, Morton Goldberg <m_goldb...@ameritech.net> 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

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

Regards, Morton