Created
April 16, 2012 18:51
-
-
Save joelpt/2400685 to your computer and use it in GitHub Desktop.
Go To Anything for Autohotkey - highlight some text, hit Win+G and "go"!
This file contains 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
;; Go to anything that is in the currently selected text: URLs, email addresses, Windows paths, or just "Google it" | |
;; Forum topic: http://www.autohotkey.com/community/viewtopic.php?f=2&t=85152&p=537116 | |
$#G:: | |
;Tip("Clipping...") ;; include my mouse-tip library for this https://gist.github.com/2400547 | |
clip := CopyToClipboard() | |
if (!clip) { | |
return | |
} | |
addr := ExtractAddress(clip) | |
if (!addr) | |
{ | |
; Google it | |
;Tip("Searching for [" SubStr(clip, 1, 50) "] ...") | |
addr := "http://www.google.com/search?q=" . clip | |
} | |
else { | |
; Go to it using system's default methods for the address | |
;Tip("Going to " Substr(addr, 1, 25) " ...") | |
} | |
Run %addr% | |
return | |
;; utility functions | |
;; Safely copies-to-clipboard, restoring clipboard's original value after | |
;; Returns the captured clip text, or "" if unsuccessful after 4 seconds | |
CopyToClipboard() | |
{ | |
; Wait for modifier keys to be released before we send ^C | |
KeyWait LWin | |
KeyWait Alt | |
KeyWait Shift | |
KeyWait Ctrl | |
; Capture to clipboard, then restore clipboard's value from before capture | |
ExistingClipboard := ClipboardAll | |
Clipboard = | |
SendInput ^{Insert} | |
ClipWait, 4 | |
NewClipboard := Clipboard | |
Clipboard := ExistingClipboard | |
if (ErrorLevel) | |
{ | |
MsgBox, The attempt to copy text onto the clipboard failed. | |
;Tip("The attempt to copy text onto the clipboard failed.") | |
return "" | |
} | |
return NewClipboard | |
} | |
;; Extracts an address from anywhere in str. | |
;; Recognized addresses include URLs, email addresses, domain names, Windows local paths, and Windows UNC paths. | |
ExtractAddress(str) | |
{ | |
if (RegExMatch(str, "S)((http|https|ftp|mailto:)://[\S]+)", match)) | |
return match1 | |
if (RegExMatch(str, "S)(\w+@[\w.]+\.(com|net|org|gov|cc|edu|info))", match)) | |
return "mailto:" . match1 | |
if (RegExMatch(str, "S)(www\.\S+)", match)) | |
return "http://" . match1 | |
if (RegExMatch(str, "S)(\w+\.(com|net|org|gov|cc|edu|info))", match)) | |
return "http://" . match1 | |
if (RegExMatch(str, "S)([a-zA-Z]:[\\/][\\/\-_.,\d\w\s]+)", match)) | |
return match1 | |
if (RegExMatch(str, "S)(\\\\[\w\-]+\\.+)", match)) | |
return match1 | |
return "" | |
} |
Very nice! I think I'll incorporate your improvements to the script in the
near future.
Thanks!
Joel
…On Thu, May 17, 2012 at 8:06 AM, John Harrison < ***@***.*** > wrote:
I like this, and I used it to write my own function for launching PuTTY
(thanks!)
I did note though that it clobbers whatever you have in your clipboard
with the text that you select.
We're only using the clipboard because it's the means we have of using the
selected text, so throwing away what you had been using in the clipboard is
a bit of an unwanted side-effect.
I found a way to use it without doing this (and I also changed the ^C to
^{Insert} which works in a terminal window too.)
Have a look here: https://gist.github.com/2710415
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/2400685
Hi,
I am a newbie here and was desperately looking for a way to send an highlighted text (not URL) to browser and bumped into this short script.
So got it. Just... I need some ABC to understand where (blush) I have to write it down, in the Developer tool in Chrome browser or?
Sorry for this "stupid" question but I'd need some tips to start with...
Thanks in advance for your patience... :)
Beppe
Hello,
I have been using this script for a while - much appreciation for sharing. However, since I've gone over to Firefox from Chrome, whenever I use the hotkey, the Firefox window is de-selected. This results in me having to click the Firefox window to continue browsing. Does anyone have an idea of how to fix this?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I like this, and I used it to write my own function for launching PuTTY (thanks!)
I did note though that it clobbers whatever you have in your clipboard with the text that you select.
We're only using the clipboard because it's the means we have of using the selected text, so throwing away what you had been using in the clipboard is a bit of an unwanted side-effect.
I found a way to use it without doing this (and I also changed the ^C to ^{Insert} which works in a terminal window too.)
Have a look here: https://gist.github.com/2710415