September 19, 2023

Hotkey or Script to enable or disable Focus Assist in Windows 10

I was looking for a solution to set the Focus Assistant mode e.g. to Do not disturb by script, at the best with AutoHotkey. I share here finally how I can do this.

Use Case description

When in a Meeting or Sharing my screen e.g. in a Microsoft Teams Meeting, I would like to switch the Windows Notifications off. (not only the Teams notifications which you can configure see here Teams: Mute notifications during Meetings and Calls)

Since I often forget about it, I would like to be able to automate this i.e. do this within a script.

Benchmark

In the Internet I couldn't find a solution for this i.e. that not only toggle the focus mode, but really set the focus mode as you command it.

The related posts I have found are:

My solution=AutoHotkey Code

Code is available in this Gist:
It is also included in my AHK repository: https://github.com/tdalon/ahk/blob/main/Lib/FocusAssist.ahk

Solution Explanation

The solution requires the UIAutomation Library provided by Descolada.

To open the Focus Assistant Settings I use a trick to open the url : ms-settings:quiethours


Using the UIA_Viewer you can identify the AutomationId for each controls to switch the Focus Mode via the Settings window.

You need to wait for the element to exist, before being able to click on it. Hence, the WaitElementExist Method is used.

Integration in Teams PowerTools

I have added this functionality now in the Teams PowerTools: when Sharing my screen, the Focus Mode is automatically set to Priority only.

Also, when you leave a meeting with the PowerTool the focus mode is deactivated.

Also in the Teams Launcher you can set the Focus Assist mode using the keyword 'fa' and + or -.

References

See also

Teams: Mute notifications during Meetings and Calls

No comments:

Post a Comment