如何在Microsoft Teams中实现未读消息弹窗提醒?
需求:New Teams未读消息弹窗提醒
我需要一个弹窗提醒,告知自己Microsoft Teams中有未读消息——哪怕坐在电脑前工作,有时也会错过Teams短暂的消息横幅长达数小时,不确定是bug,还是因为太专注或者看了错误显示器导致的。
之前我用Auto Hotkey(AHK)脚本实现过这个功能:当Teams有活动时,系统托盘里的Teams图标名称会变化,我可以定期读取图标名称并弹出提醒。但2023年推出的New Teams不再更新系统托盘图标名称,导致脚本失效。
请问在New Teams中,还有什么方法能在有人需要我关注时定期提醒我?我考虑过持续检测消息横幅,但不知道如何屏蔽已读消息的通知(这对减少干扰很重要)。我知道可以开启Teams的“每10分钟发送错过活动邮件”设置,但这类邮件同样无法有效吸引我的注意力。
旧AHK脚本代码:
SetTimer, windows_to_front, 10* 60 * 1000 ; 10分钟 windows_to_front: DetectHiddenWindows On Check_for_Teams_Notification() Check_for_Teams_Notification() { ; 来自TrayIcon.ahk -- AHK版本1 ; 遍历系统托盘里所有可能的托盘提示消息: DetectHiddenWindows, On global Username For key, sTray in ["Shell_TrayWnd","NotifyIconOverflowWindow"] { idxTB := TrayIcon_GetTrayBar() WinGet, pidTaskbar, PID, ahk_class %sTray% hProc := DllCall("OpenProcess", UInt, 0x38, Int, 0, UInt, pidTaskbar) pRB := DllCall("VirtualAllocEx", Ptr, hProc, Ptr, 0, UInt, 20, UInt, 0x1000, UInt, 0x4) SendMessage, 0x418, 0, 0, ToolbarWindow32%idxTB%, ahk_class %sTray% ; TB_BUTTONCOUNT szBtn := VarSetCapacity(btn, (A_Is64bitOS ? 32 : 24)) szNfo := VarSetCapacity(nfo, (A_Is64bitOS ? 32 : 24)) szTip := VarSetCapacity(tip, 128 * 2) Loop, %ErrorLevel% { SendMessage, 0x417, A_Index - 1, pRB, ToolbarWindow32%idxTB%, ahk_class %sTray% ; TB_GETBUTTON DllCall("ReadProcessMemory", Ptr, hProc, Ptr, pRB, Ptr, &btn, UInt, szBtn, UInt, 0) dwData := NumGet(btn, (A_Is64bitOS ? 16 : 12)) iString := NumGet(btn, (A_Is64bitOS ? 24 : 16)) DllCall("ReadProcessMemory", Ptr, hProc, Ptr, dwData, Ptr, &nfo, UInt, szNfo, UInt, 0) DllCall("ReadProcessMemory", Ptr, hProc, Ptr, iString, Ptr, &tip, UInt, szTip, UInt, 0) trayt := StrGet(&tip, "UTF-16") ; msgbox %trayt% if (inStr(trayt, "Microsoft Teams")) && (inStr(trayt, "New Activity")) { teams_msg_was_found := true ; msgbox "Found MS Teams & New Activity" } ; end if } ; end loop } ; end for if (teams_msg_was_found and !WinActive("ahk_exe Teams.exe")) { MsgBox 0x40001, APPL ALERT, "MS Teams has an alert", 60 } ; end if } ; end function
可行解决方案
1. 读取New Teams本地状态
New Teams基于Electron构建,会在本地缓存未读消息状态:
- 定期读取
%APPDATA%\Microsoft\Teams目录下的缓存文件,提取未读消息计数。当计数大于0且Teams窗口未激活时,触发弹窗提醒。 - 使用AHK的UIAutomation库,定位Teams界面侧边栏的未读红点/数字徽章,检测其存在状态来判断是否有未读消息。
2. 优化通知检测逻辑
如果选择检测消息横幅,可通过以下方式过滤已读通知:
- 记录Windows通知的唯一ID,新通知触发弹窗后保存ID,后续不再重复提醒;当打开Teams窗口时,清空已记录的ID列表。
- 仅在Teams窗口未激活时,对新通知触发弹窗,避免重复干扰。
3. 调整Teams内置设置
- 将重要对话的通知设置为**“横幅和声音”,并开启“持续显示横幅”**(路径:Teams设置>通知>消息),延长横幅展示时间。
- 配置专注助手例外规则,确保即使开启专注模式,Teams重要通知仍能正常弹出。
内容的提问来源于stack exchange,提问作者deasserted
相关产品推荐
相关产品推荐

