【问题标题】:Open, Rename, and Minimize Google Chrome Instance打开、重命名和最小化 Google Chrome 实例
【发布时间】:2019-12-17 15:02:26
【问题描述】:

所以基本上我正在尝试打开一个新的隐身 Chrome,并设置选项卡的标题,以便稍后我可以 Winactivate 它并最小化窗口。我认为这主要是我的变量“myIncog”设置和使用的问题。

这个脚本应该打开一个新的 chrome 隐身,命名 标签,打开一个新标签。然后,稍后,我想激活该选项卡,最小化整个窗口并静音。

不起作用的部分是找到并激活我设置的 WinSetTitle。

^0::
Run, C:\Program Files (x86)\Google\Chrome\Application\chrome.exe " --incognito" ; works
WinActivate  ; works but probably not necessary
WinSetTitle, myIncog  ; I don't know if this works
Sleep, 1000  ; works
Send ^t  ; works - opens new tab
Return


^+0::
ifWinExist, myIncog ; no
{
MsgBox, HI! ; nope - so I know the ifWinExist does not know my WinSetTitle name 'myIncog'
WinActivate ; nope
SoundSet, +1, , mute  ; works
WinMinimize ; no
}
Return

提前致谢!

【问题讨论】:

  • 一种解决方法是使用窗口句柄hwnd 来唯一选择窗口,或者即使在启动进程时,您也可以指定Run 给您进程的PID

标签: autohotkey


【解决方案1】:

所以,你可以试试这样的:

^0::
    SetTitleMatchMode, 2 ; Match a window that contains WinTitle anywhere 
    Run, "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --incognito

    ; Wait for the new chrome window to be created
    WinWait, - Google Chrome ahk_class Chrome_WidgetWin_1

    ; Store the hwnd for the window in a variable "chrome"
    WinGet, chrome, ID, - Google Chrome ahk_class Chrome_WidgetWin_1

    ; Activate the window using the hwnd
    WinActivate, ahk_id %chrome%

    Send {ctrl down}t{ctrl up} ; ^t should work fine, but this is less likely to let me down
    ; This could even be done with ControlSend, removing the need for WinActivate
Return

^+0::
    If WinExist("ahk_id " chrome)
    {
        MsgBox, HI!
        ; Again use the hwnd for chrome that was saved in the global variable earlier
        WinActivate ahk_id %chrome% 
        SoundSet, +1, , mute
        WinMinimize ahk_id %chrome%
    }
Return

您可以根据需要修改它使用的 WindowTitle,但请注意,正如您所注意到的,尝试使用 WinSetTitle 设置它充其量只是暂时的。

导航到新网站,甚至更改选项卡,都会清除您使用 WinSetTitle 设置的任何内容。因此,最好使用更稳定的值,例如 hwnd,正如 Joe 在对该问题的评论中提到的那样。

顺便说一句,您可以考虑使用additional launch flags 来满足您的部分或全部需求,例如添加“--new-window”和/或“--mute-audio”。您可能已经知道这一点,但您还可以指定一个 url,甚至您是否希望它从一开始就最小化(甚至完全隐藏)启动它。

例如,另一种带有更完善的运行命令的方法可能如下所示:

If !WinExist("- Google Chrome ahk_class Chrome_WidgetWin_1")
    Run, "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --incognito --mute-audio --new-window "about:blank",, Min

【讨论】:

    猜你喜欢
    • 2022-08-19
    • 1970-01-01
    • 2021-05-26
    • 2014-01-04
    • 2016-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多