Skip to content

Instantly share code, notes, and snippets.

@b-coimbra
Created August 25, 2017 16:01
Show Gist options
  • Save b-coimbra/25900dfda0d9f871799b46c723df5c59 to your computer and use it in GitHub Desktop.
Save b-coimbra/25900dfda0d9f871799b46c723df5c59 to your computer and use it in GitHub Desktop.
opens google and types something
#!/usr/bin/env ruby
# encoding: UTF-8
# USAGE: ruby google.rb <anything you want to search>
require 'win32ole'
shell = WIN32OLE.new("Wscript.Shell")
link = "www.google.com"
link =~ /www\.(.*)\.com/i
title = $1.capitalize
case RbConfig::CONFIG['host_os']
when /mswin|mingw|cygwin/im
system "start #{link}"
when /darwin/im
system "open #{link}"
when /linux|bsd/im
system "xdg-open #{link}"
end
sleep 2
(shell.Run(title); sleep 0.5) if !shell.AppActivate(title)
shell.SendKeys(ARGV.join(' ') + "{ENTER}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment