我怎样才能用AutoHotkey的脚本当前浏览器的网址? [英] How can I get the current browser URL with an AutoHotKey script?

查看:1234
本文介绍了我怎样才能用AutoHotkey的脚本当前浏览器的网址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找一个AutoHotkey的方式把当前所访问的URL中的变量。这个AHK的目标是要追溯到我白天在做什么,可以登录我的时间更好。我还有一个系统,我用我的时钟工作,但soetimes我忘记使用它时,我得到扯到。

 循环
{
    ;获取当前窗口ID&安培;名称
    温格特,active_id,ID,A
    温格特,PROCESS_NAME,ProcessName,A    ;只有当任何其他窗口被激活做任何事
    如果(active_id = prevActiveId)
    {
        ;没做什么
    }
    其他
    {
        ;格式化的时间戳。
        电流=%A_DD%/%A_MM%/%A_YYYY%,%A_Hour%:%A_Min%        ;写这个数据到log.txt文件。
        fileappend,当前%% - %PROCESS_NAME%`N,log.txt的        ;获取URL,如果PROCESS_NAME =的chrome.exe
        如果(PROCESS_NAME =的chrome.exe)
        {
            ;把网址中的日志文件
            ; fileappend,当前%% - %current_url%`N,log.txt的
        }
    }    prevActiveId =%active_id%
    睡觉时,100
}


解决方案

有关浏览器,获得控制Chrome_OmniboxView1,它是多功能框(作为当前版本的Chrome,21.0.1180.83)的文本。

这code使多功能框的内容到变量omniboxContents:

  ControlGetText omniboxContents,Chrome_OmniboxView1,铬

注意omniboxContents不一定包含一个正确的URL,因为HTTP://被冷落如果URL以http://开头。因此,而不是http://www.google.com,你会得到www.google.com,这严格来说不是一个正确的URL。这完全是因为Chrome会显示地址在多功能框的方式。你将不得不增加额外的code,以获得多功能框的内容的正确的URL。

I'm looking for a way in AutoHotkey to put the currently visited url in a variable. The goal of this AHK is to trace back what I've been doing during the day to be able to log my hours better. I have another system which I use to clock my work, but soetimes 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
}

解决方案

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

This code puts the content of the omnibox into the variable omniboxContents:

ControlGetText omniboxContents, Chrome_OmniboxView1, Chrome

Note that omniboxContents doesn't necessarily contain a correct URL, because "http://" is left out if the URL starts with "http://". So instead of "http://www.google.com" you will get "www.google.com", which strictly speaking isn't a correct URL. This is simply because Chrome shows the address that way in the Omnibox. You will have add extra code to get a correct URL from the contents of the omnibox.

这篇关于我怎样才能用AutoHotkey的脚本当前浏览器的网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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