Sunday, July 10, 2011

Run Sikuli in (J)Ruby - (J)IRB

I use irb for composing and debugging scripts. Following is what you might need to do inorder to run Sikuli in  IRB:
  1. Install JRuby or via rvm
  2. Copy sikuli-script.jar to  jruby lib
    • cp /Applications/ $JRUBY_HOME/lib
    • For RVM:
      • rvm list (to list currently installed rubies)
      • rvm use jruby-1.x.x (to use jruby as the ruby implementation)
      • rvm info (to print information about the ruby currently being used)
      • cp /Applications/ $MY_RUBY_HOME/lib ($MY_RUBY_HOME points to the current ruby home, in this case jruby)
  3. run irb (the irb prompt should list jruby as the ruby implementation, something like jruby-1.x.x :001 >  )
  4. jruby-1.x.x :001 > require 'java'                                                                                      
    •  => true 
  5. jruby-1.x.x :002 > java_import 'org.sikuli.script.Screen'                                                              
    •  => Java::OrgSikuliScript::Screen 
  6. jruby-1.x.x :003 > screen =                                                                             
    •  => #<Java::OrgSikuliScript::Screen:0x1dc2dad7>
  7. jruby-1.6.0 :004 > image_path='/Users/mubbashir/Desktop'                                                             
    •  => "/Users/mubbashir/Desktop"
  8. screen.hover("#{image_path}/apple.png") 
    • [info] Sikuli vision engine loaded.
    •  => 1 
 You will see mouse pointer to be moved to apple icon.

With Auto Completion IRB is just a blessing, specially when you want to try some new library or need to run some snippets:

Similarly in script it would be something like:

to run the script ruby script_file_name.rb Just be sure that you are using JRuby ;)

No comments:

Post a Comment