formats

Open Clipboard Contents Hotkey

Published on August 30, 2011
I find it particularly useful to be able to copy a file, folder, URL, or search term to the clipboard and then with one hotkey, open it up.  Here is the script I use with AutoHotkey to assign Win+O to open whatever’s in the clipboard. First it checks to see if the clipboard contains a file, folder, or program that exists on disk.  If not, does is it appear to be a URL?  And if still not, just Google the clipboard contents.
; Execute the contents of the clipboard. Set browser to your preferred browser.
browser := userprofile "\Local Settings\Application Data\Google\Chrome\Application\chrome.exe"
#o::
  contents = %clipboard%
  StringSplit, SplitArray, contents, `n
  Loop, %SplitArray0%
  {
    _line := SplitArray%a_index%
   
    ; First attempt a shell execute
    Run, %_line%,, UseErrorLevel

    ; If that didn't work, try something else
    if (ErrorLevel = "ERROR")
    {
      ; Does the clipboard contain a URL?
      FoundPos := RegExMatch(_line, "A)\w[^\s]*\.(?:com|co|uk|gov|edu|tv|net|org|tel|me|us|mobi|es)(?:\z|/.*)\z")
      if FoundPos
        Run %browser% %_line%
      else
        Run http://www.google.com/search?q=%_line%
    }
  }
return
It is also designed to open multiple items if separated by a carriage return, for example:
http://coad.net
http://facebook.com
http://noahcoad.com
 
 Share on Facebook Share on Twitter Share on Reddit Share on LinkedIn
No Comments  comments 

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

© Noah Coad
credit