Created
August 25, 2017 16:01
-
-
Save b-coimbra/25900dfda0d9f871799b46c723df5c59 to your computer and use it in GitHub Desktop.
opens google and types something
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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