Rip the URL from the Clipboard with AutoHotkey

Someone asked me if I had a tool that would look at the clipboard and return only the URL or Rip the  URL from the Clipboard. (The clipboard has various formats like: Files, Text, Rich Text Format, HTML, Images, etc.).

I used the cool WinClip library which can be grabbed here: https://autohotkey.com/board/topic/74670-class-winclip-direct-clipboard-manipulations/ and, with the help of maestrith, wrote a script which returns the various items on the clipboard in HTML format as an object.

Rip the URL from the Clipboard

 
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#SingleInstance,Force
SetBatchLines,-1
global Com:=ComObjCreate(“HTMLFile”)
;*******************************************************
Browser_Back:: ;Change this hotkey to what you want
CB:=ClipboardAll
Clipboard:=””
while(Clipboard){
Sleep,10
}
Send,^c
while(!Clipboard){
Sleep,10
}
Clip:=Get_Clipboard_Data() ;Call the function and return the HTML data in an object
MsgBox % clip.1.HREF
DebugWindow(Obj2String(Clip),1,1,200,0)
Clipboard:=CB ;restore Clipboard
return

;********************Grab data from Clipboard***********************************
Get_Clipboard_Data(){
wc := new WinClip
wc.iSnap()
Obj:=[]
try:=wc.iGetHTML()
HTML:=SubStr(Try,InStr(Try,”<HTML>”))
Com.Close()
Com.Write(HTML)
All:=Com.GetElementsByTagName(“a”)
Url:=[]
RegExMatch(Try,”OUi)SourceURL:(.*)\R”,Found)
while(aa:=All.Item[A_Index-1]){
URL.Push({Page:Found.1,Text:aa.InnerText,HREF:aa.HREF})
}
return URL
}
;~ https://autohotkey.com/board/topic/74670-class-winclip-direct-clipboard-manipulations/
#Include B:\Progs\AutoHotkey_L\AHK Work\WinClip\WinClipAPI.ahk
#Include B:\Progs\AutoHotkey_L\AHK Work\WinClip\WinClip.ahk

Comments are closed.