Skip to content

Instantly share code, notes, and snippets.

Last active March 15, 2016 04:40
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Ruby script to open the contents of the clipboard. Just assign it to a global hotkey, like Ctrl+O, using Sparkle, Quicksilver, Alfred Powerpack, or your favorite hotkey app. Copy something to the clipboard, hit the hotkey, and it's opened up.
#!/usr/bin/env ruby
# Opens the clipboard contents
# 1. Is it a file or folder?
# 2. Is it obviously a URL?
# 3. Google It
# clipboard contents
clip = IO.popen('pbpaste', 'r+').read
# open appropriately
if File.exist? clip
system("open", clip)
elsif /\w[^\s]*\.(?:com|co|uk|gov|edu|tv|net|org|tel|me|us|mobi|es|io)(?:[ \r\n]{0,2}\z|\/.*)[ \r\n]{0,2}\z/.match(clip)
clip = "http://#{clip}" unless (clip.index '://')
system("open -a 'Google Chrome' #{clip}")
google = "{clip}"
system("open -a 'Google Chrome' '%s'" % [google])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment