如何解决使用 Chrome 激活 Gmail 消息或打开新的 Gmail 消息窗口
我正在尝试切换到我的新 gmail 消息框,但如果它不存在,我希望我的脚本打开 gmail 并打开一封新电子邮件(撰写新邮件)。 这是我现有的脚本(之前由 user285594 提供)
^+m::
SetTitleMatchMode,2
WinTitleC :="Compose Mail - "
IfWinExist,%WinTitleC%
{
WinActivate
return
}else{
SetTitleMatchMode,2
IfWinExist,Chrome
WinActivate ;
WinWait,Chrome ;
sleep,100 ;
chrome := "- Google Chrome"
found := "false"
tabSearch := "gmail"
curWinNum := 0
WinGet,numOfChrome,Count,%chrome% ; Get the number of chrome windows
WinActivateBottom,%chrome% ; Activate the least recent window
WinWaitActive %chrome% ; Wait until the window is active
ControlFocus,Chrome_RenderWidgetHostHWND1 ; Set the focus to tab control ???
while (curWinNum < numOfChrome and found = "false") {
WinGetTitle,firstTabTitle,A ; The initial tab title
title := firstTabTitle
Loop {
if(InStr(title,tabSearch)>0){
found := "true"
break
}
Send {Ctrl down}{Tab}{Ctrl up}
Sleep,50
WinGetTitle,title,A ;get active window title
if(title = firstTabTitle){
break
}
}
WinActivateBottom,%chrome%
curWinNum := curWinNum + 1
}
ControlSend,{Shift Down}c{Shift Up},Google Chrome
winmove,Compose,1750,303,1725,935 ; moving the window to my preferred position
if(found = "false"){
run C:\Program Files (x86)\Google\Chrome\Application\chrome.exe https://mail.google.com/mail/u/0/?ogbl#inbox
WinWait,Inbox
ControlSend,{Shift Down}c,Google Chrome
winmove,935; moving the window to my preferred position
}
}
return
无论我在哪个选项卡中,当我打开 chrome 时它都可以工作。如果最小化 chrome,它不起作用并且似乎暂停。你有什么建议?
解决方法
我认为错误在于这一行:
WinGetTitle,firstTabTitle,A ; The initial tab title
这是一个解决方案建议:
#SingleInstance force
SetTitleMatchMode,2
ComposeTitle = Compose Mail -
If WinExist(ComposeTitle . " ahk_exe chrome.exe") {
WinActivate
return
}
; Loop on all Chrome Windows
WinGet,id,List,ahk_exe Chrome.exe
found := False
tabSearch = Gmail
Loop,%id%
{
hWnd := id%A_Index%
WinActivate,ahk_id %hWnd%
; Loop on all Tabs in Chrome Window
WinGetTitle,A
title := firstTabTitle
Loop {
if (InStr(title,tabSearch)>0){
found = True
break
}
Send ^{Tab} ; switch to next tab
Sleep,50
WinGetTitle,title,A ;get active window title
if (title = firstTabTitle){
break
}
} ; end Loop Tabs
if (found)
break
} ; end loop Chrome windows
If !(found) {
Run run C:\Program Files (x86)\Google\Chrome\Application\chrome.exe https://mail.google.com/mail/ca/u/0/#inbox"
WinWait,Inbox ahk_exe Chrome.exe
}
SendInput +c ; Shift+C
;WinWait %ComposeTitle%
;winmove,A,1750,303,1725,935; moving the window to my preferred position
return
您可以从 this gist 下载代码。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。