Created
April 16, 2012 18:34
-
-
Save joelpt/2400562 to your computer and use it in GitHub Desktop.
Type <sitename>@mydomain.com in Google Chrome for Autohotkey
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
;; Chrome has been seen with any of these class names | |
GroupAdd, GoogleChrome, ahk_class Chrome_WindowImpl_0 | |
GroupAdd, GoogleChrome, ahk_class Chrome_WidgetWin_0 | |
GroupAdd, GoogleChrome, ahk_class Chrome_WidgetWin_1 | |
;; My email domain name | |
EmailDomainName := "mydomain.com" | |
;; Send [email protected] | |
#IfWinActive ahk_group GoogleChrome | |
#+A:: | |
SetTitleMatchMode, Slow | |
WinGetText, addr, A | |
addr := RegExReplace(addr, "s).*\n(.+)", "$1") | |
addr := ExtractAddress(addr) | |
addr := RegExReplace(addr, "^.+\n(.+)$", "$1") | |
addr := RegExReplace(addr, "^.*https?://", "") | |
addr := RegExReplace(addr, "/.+$", "") | |
addr := RegExReplace(addr, "(.+)\.\w+?[/\?].+?$", "$1") | |
addr := RegExReplace(addr, "^(\w+)\.(\w+)\.(\w+)$", "$2") | |
addr := RegExReplace(addr, "^(\w+)\.(\w+)$", "$1") | |
addr := RegExReplace(addr, "^\s*(.+)\s*$", "$1") | |
addr := addr . "@" . EmailDomainName | |
Send %addr% | |
return | |
#IfWinActive | |
;; utility functions | |
ExtractPath(str) | |
{ | |
; This probably needs to be broken into a path regex and a path+filename regex, so we can | |
; do some kind of file extension check first and drop possible crap from the end of it | |
output := "" | |
str := RegExReplace(str, "Address:", "") ; known cleanup for Win Explorer and perhaps others (wants to match s:) | |
str := " " str " " | |
if (RegExMatch(str, "S)[\s\n](([a-zA-Z]:|\\\\\w+)([\\/]([\w \d\-\.]+\$?))*)", match)) ; local/UNC path | |
{ | |
path := match1 | |
if (InStr(FileExist(path), "D")) | |
{ | |
output := path "\" | |
} | |
else | |
{ | |
path := RegExReplace(path, "(.+)[\\/].*", "$1") | |
if (InStr(FileExist(path), "D")) | |
{ | |
output := path "\" | |
} | |
} | |
} | |
return output | |
} | |
ExtractPathFromWindow(pattern) | |
{ | |
return ExtractPath(WinGetTitle(pattern) "`n" WinGetText(pattern)) | |
} | |
;; 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 "" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment