Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
iTerm and Ruby::OSA
Matt Mower
10/28/2007 5:27:00 PM
Hi.
I wonder if anyone has successfully gotten iTerm to open a new session
within a terminal window and execute commands using RubyOSA?
http://rubyosa.ruby...
I can do this from the Apple ScriptEditor but not using OSA. The
problem, in a nutshell, is that
iterm = OSA.app( 'iTerm' )
returns an instance of OSA::ITerm::Application where all of the useful
methods for working with terminals & sessions are in
OSA::ITerm::ITermApplication and I cannot seem to find out how to go
from one to the other. (My primary sources of info are the RubyOSA
docs, the output of rdoc-osa --name iTerm, and Google).
I note that this distinction is not visible in ScriptEditor and that
pointing OSA at another app (e.g. iTunes as in the examples for OSA)
seems to yield an immediately useful application object.
Is this perhaps a problem with iTerm not supporting introspection
properly (even if ScriptEditor can do it)? Or maybe a bug in RubyOSA?
If anyone can help me I'd be much obliged.
Regards,
Matt
--
Matt Mower ::
http://matt...
3 Answers
hengist podd
10/29/2007 12:50:00 AM
0
On 28 Oct, 17:27, "Matt Mower" <matt.mo...@gmail.com> wrote:
> Hi.
>
> I wonder if anyone has successfully gotten iTerm to open a new session
> within a terminal window and execute commands using RubyOSA?
>
>
http://rubyosa.ruby...
>
> I can do this from the Apple ScriptEditor but not using OSA. The
> problem, in a nutshell, is that
>
> iterm = OSA.app( 'iTerm' )
>
> returns an instance of OSA::ITerm::Application where all of the useful
> methods for working with terminals & sessions are in
> OSA::ITerm::ITermApplication and I cannot seem to find out how to go
> from one to the other.
Unlike AppleScript, which is very more forgiving of imperfect
dictionaries, RubyOSA strictly enforces the structure and content
provided by application dictionaries. As a result, any bugs or quirks
in an application's dictionary may prevent RubyOSA from accessing some
or all of that application's scripting features.
Anyway, I think your best solution here would be to use rb-appscript -
see my sig for links. Appscript is designed to mimic the way that
AppleScript operates as closely as possible, so application
compatibility problems are rare. For example, to echo 'hello world' in
every session tab of the current terminal window:
require 'appscript'
include Appscript
Iterm = app('iTerm')
p Iterm.current_terminal.sessions.write(:text=>'echo "hello world"')
HTH
has
--
http://appscript.sourc...
http://rb-appscript.rub...
Matt Mower
10/29/2007 9:59:00 AM
0
On 29/10/2007, has <has.temp3@virgin.net> wrote:
> Unlike AppleScript, which is very more forgiving of imperfect
> dictionaries, RubyOSA strictly enforces the structure and content
> provided by application dictionaries. As a result, any bugs or quirks
> in an application's dictionary may prevent RubyOSA from accessing some
> or all of that application's scripting features.
Thanks Has -- it does seem like Appscript is the way to go.
After some experimenting I came up with the following, that addresses
my need to create a new tab in the current iTerm window and execute a
command in it:
require 'rubygems'
require 'appscript'
iterm = Appscript::app('iTerm')
session = iterm.current_terminal.sessions.end.make( :new => :session )
session.exec( :command => "bash" )
session.write( :text => "echo 'Hello World'" )
Being unfamiliar with Appscript as well as AppleScript in general it
took me a few tries to to go from your example to making a new session
and executing a command. The key was to appreciate that Appscript
follows script dictionary closely and
uses the literal AppleScript parameters passed in hashes.
Many thanks again for your help and suggestion of using Appscript :-)
Regards,
Matt
--
Matt Mower ::
http://matt...
hengist podd
10/29/2007 10:59:00 AM
0
On 29 Oct, 09:58, "Matt Mower" <matt.mo...@gmail.com> wrote:
> Being unfamiliar with Appscript as well as AppleScript in general it
> took me a few tries to to go from your example to making a new session
> and executing a command. The key was to appreciate that Appscript
> follows script dictionary closely and
> uses the literal AppleScript parameters passed in hashes.
If you've installed from gem, you might want to grab a copy of
the .zip distribution as well to get the documentation and examples
[1]. The appscript manual includes a tutorial that should help you get
started.
I'd also recommend getting ASDictionary and ASTranslate if you've not
already done so; see <
http://rb-appscript.ruby...
downloads.html>.
HTH
has
[1] RubyGems does include all this stuff in the installed gem as well,
but you have to go hunting around your Ruby installation to find it
yourself.
--
http://appscript.sourc...
http://rb-appscript.rub...
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
iTerm and Ruby::OSA
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password