如何使用AutoHotKey脚本获取当前浏览器URL?

mas*_*m79 8 browser autohotkey

我在AutoHotkey中寻找一种方法将当前访问的url放在变量中.

这个AHK的目标是追踪我白天做的事情,以便更好地记录我的工作时间.我有另一个系统,我用来为我的工作计时,但有时我忘记使用它,当我得到侧面跟踪.

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
}
Run Code Online (Sandbox Code Playgroud)

was*_*ard 6

我用过的所有浏览器都支持Alt+D来聚焦和选择 URL。Ctrl以下是我的 AHK 脚本,通过按+ Shift+ ..复制 Google Chrome、Firefox 和 Internet Explorer 中的当前选项卡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's 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's shortcut to duplicate tab (Control+K)
   Sleep 100

   Send ^{TAB} ; Switch to that tab
}
Run Code Online (Sandbox Code Playgroud)


tum*_*tya 4

或者你可以使用F6.

大多数浏览器都会在按 时进入地址栏并为您选择整个 URL F6

然后就是复制粘贴的问题了。

对于较新的 Firefox 版本,它是Ctrl+ L

为此,您可以检查窗口标题。