[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Send keystrokes to Firefox or Safari?

Stedwick

2/17/2008 3:40:00 AM

Is there a way to send keystrokes to Firefox or Safari on Mac OS X
Leopard using Ruby? I don't want to remote control the web using watir
or anything, I just want to send keystrokes (ie. I want to be able to
type into a text box really fast hehe).

Anyone know how to do this? Thanks!
8 Answers

John Joyce

2/17/2008 4:41:00 PM

0


On Feb 16, 2008, at 9:44 PM, Stedwick wrote:

> Is there a way to send keystrokes to Firefox or Safari on Mac OS X
> Leopard using Ruby? I don't want to remote control the web using watir
> or anything, I just want to send keystrokes (ie. I want to be able to
> type into a text box really fast hehe).
>
> Anyone know how to do this? Thanks!
>
You will need to use AppleEvents, specifically System Events, and
AppleScript.
You'll want to use rb-appscript as the Ruby library for AppleScript.
Get ready for a lot of stumbling in the dark...

7stud --

2/17/2008 11:20:00 PM

0

Philip Brocoum wrote:
> Is there a way to send keystrokes to Firefox or Safari on Mac OS X
> Leopard using Ruby? I don't want to remote control the web using watir
> or anything, I just want to send keystrokes (ie. I want to be able to
> type into a text box really fast hehe).
>
> Anyone know how to do this? Thanks!

You have to realize that Safari is a software program on your computer.
What you want to do involves mucking around in the internals of that
software program.

Watir is a completely different story. Watir merely mimics what Safari
does. Watir sends the same requests as Safari does out over the
internet and then receives the same responses as Safari.
--
Posted via http://www.ruby-....

Stedwick

2/18/2008 12:41:00 AM

0

Well, how about this: is there something like AutoIt for the Mac (if I
can control it with Ruby, so much the better)?

I tried rb-appscript already, but I couldn't figure out how to send
keystrokes =P

Dick Davies

2/18/2008 10:52:00 AM

0

On Feb 17, 2008 11:20 PM, 7stud -- <bbxx789_05ss@yahoo.com> wrote:
> Philip Brocoum wrote:
> > Is there a way to send keystrokes to Firefox or Safari on Mac OS X
> > Leopard using Ruby? I don't want to remote control the web using watir
> > or anything, I just want to send keystrokes (ie. I want to be able to
> > type into a text box really fast hehe).
> >
> > Anyone know how to do this? Thanks!
>
> You have to realize that Safari is a software program on your computer.
> What you want to do involves mucking around in the internals of that
> software program.

No, you just need to feed events into it via AppleScript or somesuch.

> Watir is a completely different story. Watir merely mimics what Safari
> does. Watir sends the same requests as Safari does out over the
> internet and then receives the same responses as Safari.

No it doesn't - it scripts actions and drives Safari (or Internet Explorer, or
firefox). See:

http://safariwatir.rubyforge.org/safariwatir_script...


--
Rasputnik :: Jack of All Trades - Master of Nuns
http://number9.helloope...

Karl von Laudermann

2/18/2008 1:59:00 PM

0

On Feb 17, 7:41 pm, Stedwick <philip.broc...@gmail.com> wrote:
> Well, how about this: is there something like AutoIt for the Mac (if I
> can control it with Ruby, so much the better)?
>
> I tried rb-appscript already, but I couldn't figure out how to send
> keystrokes =P

There's also rubyosa as an alternative to rb-appscript. (But I have
not used it and couldn't tell you anything about it.)

Another option is to use JRuby, so you have access to Java's API
library, and then use Java's Robot class to send keystrokes. (http://
java.sun.com/j2se/1.5.0/docs/api/java/awt/Robot.html) Unlike with
Applescript, there's no way to send events to a specific app; you just
have to make sure that Safari is the active app at the time your
script "types" the keys.

hengist podd

2/18/2008 3:37:00 PM

0

On 18 Feb, 00:41, Stedwick <philip.broc...@gmail.com> wrote:
> Well, how about this: is there something like AutoIt for the Mac (if I
> can control it with Ruby, so much the better)?
>
> I tried rb-appscript already, but I couldn't figure out how to send
> keystrokes =P

See: http://www.apple.com/applescript/uiscripting/...

The sample scripts given there are written for AppleScript, obviously,
but could be translated to Ruby with a little work. (Hint:
ASDictionary and ASTranslate are your friends.)

Example:

#!/usr/bin/ruby

begin; require 'rubygems'; rescue ImportError; end
require 'appscript'
include Appscript

app('Safari').activate
app('System Events').keystroke('Your text here')


GUI scripting is crude and fragile, but can be useful when dealing
with applications that don't provide a proper scripting API for the
features you need.

You can also script Safari directly, including executing your own
JavaScripts via its 'do JavaScript' command. (This is what SafariWatir
[http://safariwatir.ruby...] does.) Dunno about Firefox as I
don't use it myself, but maybe someone else will know.

HTH

has
--
http://appscript.sourc...
http://rb-appscript.rub...

Stedwick

2/18/2008 8:12:00 PM

0

>> app('System Events').keystroke('Your text here')

I think this is what I'm looking for, thanks!

Kajan Sittampalam

12/25/2008 12:31:00 PM

0

Hi,

how can i send keystokes to a flash object (i.e. Textbox) in Internet
explorer? at the moment all i can do is send words to normal HTML pages.
Thanks in advance.

Kajan.



hengist podd wrote:
> On 18 Feb, 00:41, Stedwick <philip.broc...@gmail.com> wrote:
>> Well, how about this: is there something like AutoIt for the Mac (if I
>> can control it with Ruby, so much the better)?
>>
>> I tried rb-appscript already, but I couldn't figure out how to send
>> keystrokes =P
>
> See: http://www.apple.com/applescript/uiscripting/...
>
> The sample scripts given there are written for AppleScript, obviously,
> but could be translated to Ruby with a little work. (Hint:
> ASDictionary and ASTranslate are your friends.)
>
> Example:
>
> #!/usr/bin/ruby
>
> begin; require 'rubygems'; rescue ImportError; end
> require 'appscript'
> include Appscript
>
> app('Safari').activate
> app('System Events').keystroke('Your text here')
>
>
> GUI scripting is crude and fragile, but can be useful when dealing
> with applications that don't provide a proper scripting API for the
> features you need.
>
> You can also script Safari directly, including executing your own
> JavaScripts via its 'do JavaScript' command. (This is what SafariWatir
> [http://safariwatir.ruby...] does.) Dunno about Firefox as I
> don't use it myself, but maybe someone else will know.
>
> HTH
>
> has

--
Posted via http://www.ruby-....