How to get current browser URL using AutoHotKey script?

I am looking for a way in AutoHotkey to place the current URL in a variable.

The purpose of this AHK is to track what I did during the day to better record hours. I have another system that I use to keep track of my work, but sometimes I forget to use it when I get lateral tracking.

loop { ; Get current Window ID & Name WinGet, active_id, ID, A WinGet, process_name, ProcessName, A ; Only do anything if any other windows was activated if(active_id = PrevActiveId) { ; Do nothing } else { ; Format the time-stamp. current=%A_DD%/%A_MM%/%A_YYYY%, %A_Hour%:%A_Min% ; Write this data to the log.txt file. fileappend, %current% - %process_name%`n, log.txt ; Get the URL if process_name = "chrome.exe" if(process_name = "chrome.exe") { ; Put URL in log file ; fileappend, %current% - %current_url%`n, log.txt } } PrevActiveId = %active_id% Sleep, 100 } 
+8
source share
7 answers

For Chrome, get the text of the Chrome_OmniboxView1 control, which is omnibox (as for the current version of Chrome, 21.0.1180.83).

This code places the contents of the omnibox in the omniboxContents variable:

 ControlGetText omniboxContents, Chrome_OmniboxView1, Chrome 

Note that omniboxContents does not necessarily contain the correct URL because "http: //" is not taken into account if the URL starts with "http: //". Therefore, instead of "http://www.google.com" you will get "www.google.com", which, strictly speaking, is not a valid URL. This is simply because Chrome displays the address in this way in Omnibox. You will have additional code added to get the correct URL from the omnibox content.

+4
source

All the browsers I used support Alt + D to focus and select the URL. Here are my AHK scripts that duplicate the current tab in Google Chrome, Firefox, and Internet Explorer by pressing Ctrl + Shift + D ..

 #IfWinActive ahk_class MozillaUIWindowClass ; Mozilla Firefox 3.x ^+d::GenericDuplicateTab() ; (Control+Shift+D) #IfWinActive #IfWinActive ahk_class MozillaWindowClass ; Firefox 4, 5, 6, 7, 8+ (?) ^+d::GenericDuplicateTab() ; (Control+Shift+D) #IfWinActive #IfWinActive ahk_class Chrome_WidgetWin_1 ; Chromium and Chrome 19+ ^+d::GenericDuplicateTab() ; (Control+Shift+D) #IfWinActive #IfWinActive ahk_class Chrome_WidgetWin_1 ; Chrome 18 and less ^+d::GenericDuplicateTab() ; (Control+Shift+D) #IfWinActive #IfWinActive ahk_class IEFrame ^+d::InternetExplorerDuplicateTab() ; (Control+Shift+D) #IfWinActive GenericDuplicateTab() { ; Wait for both Control and Shift to be released. KeyWait Control KeyWait Shift BackupClipbrd := Clipboard Sleep 50 Send !d ; Select the url textbox Sleep 150 Send ^x ; Copy the url ClipWait 0.1 If ERRORLEVEL { Clipboard := BackupClipbrd Return } Send ^t ; Open a new tab Sleep 50 Send ^v ; Paste the url into the new tab url textbox Sleep 50 Send {Enter} Clipboard := BackupClipbrd } InternetExplorerDuplicateTab() { ; Wait for both Control and Shift to be released. KeyWait Control KeyWait Shift Send ^k ; Call IE shortcut to duplicate tab (Control+K) Sleep 100 Send ^{TAB} ; Switch to that tab } 
+3
source

Or you can use F6 .

Most browsers fall into the address bar and select the entire URL for you when they press F6 .

Then it's just a copy-paste question.

For newer versions of Firefox its Ctrl + L though.

To do this, you can check the window title.

+2
source

A clean way to do this:

  GroupAdd, WebBrowsers, ahk_class MozillaWindowClass GroupAdd, WebBrowsers, ahk_class IEFrame GroupAdd, WebBrowsers, ahk_class Chrome_WidgetWin_0 GroupAdd, WebBrowsers, ahk_class Chrome_WidgetWin_1 GroupAdd, WebBrowsers, ahk_class OperaWindowClass GroupAdd, WebBrowsers, ahk_class {1C03B488-D53B-4a81-97F8-754559640193} ; etc. #IfWinActive, ahk_group WebBrowsers { ^+d:: ; [Instructions...] return }#If 
+1
source

It is also possible to do this without relying on the clipboard, by directly monitoring the actual components that make up the browser window. Additional information: http://www.autohotkey.com/board/topic/111114-get-the-url-of-the-current-active-browser-tab/ . This method is much more efficient, but uses OS APIs.

+1
source

Use the WinGetTitle function, as most browsers set the current URL in the header.

 loop { ; Get current Window ID & Name WinGet, active_id, ID, A WinGet, process_name, ProcessName, A WinGetTitle, this_title, ahk_id %active_id% ; Format the time-stamp. current=%A_DD%/%A_MM%/%A_YYYY%, %A_Hour%:%A_Min% ; Only do anything if any other windows was activated if(active_id = PrevActiveId) { if process_name contains chrome.exe,firefox.exe,iexplore.exe,flock.exe,k-meleon.exe,javaw.exe { ; Write titles to the log.txt file. fileappend, %current% - %process_name% - %this_title%`n, log.txt } } else { ; Write titles to the log.txt file. fileappend, %current% - %process_name% - %this_title%`n, log.txt } Sleep, 1000 PrevActiveId = %active_id% } 
0
source

You can use the Alt + D shortcut to activate the address bar and then copy the URL using the Ctrl + C shortcut

 F1:: { Send, !d Sleep 50 Send, ^c Sleep 50 Return } 
0
source

All Articles