如何使用 AutoHotKey 脚本获取当前浏览器 URL? [英] How can I get the current browser URL with an AutoHotKey script?

查看:27
本文介绍了如何使用 AutoHotKey 脚本获取当前浏览器 URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm looking for a way in AutoHotkey to put the currently visited url in a variable.

此 AHK 的目标是跟踪我白天所做的事情,以便更好地记录我的工作时间.我有另一个系统用来计时我的工作,但有时我会在偏离轨道时忘记使用它.

The goal of this AHK is to trace what I've been doing during the day to log my hours better. I have another system which I use to clock my work, but sometimes I forget to use it when I get side-tracked.

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
}

推荐答案

我用过的所有浏览器都支持 Alt+D 来聚焦和选择 url.这是我的 AHK 脚本,通过按 Ctrl+Shift+D..<在 Google Chrome、Firefox 和 Internet Explorer 中复制当前选项卡/p>

All browsers that I've used support Alt+D to focus and select the url. Here are my AHK scripts that duplicates 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'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
}

这篇关于如何使用 AutoHotKey 脚本获取当前浏览器 URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆