October 23, 2023

Teams New: Switch Tenant with a Hotkey

Introduction

Request





Solution Idea


Using the UIAutomation Library

Click on the Avatar: AutomationId: idna-me-control-avatar-trigger

Click on the Menu on the bottom to Switch - Find by Name/Type

AutoHotkey Code

Code is available in the Teams Library Lib/Teams.ahk -> Teams_SwitchTenant function
Teams_SwitchTenant(sTenant) {
WinId := Teams_GetMainWindow()
If !WinId ; empty
return
UIA := UIA_Interface()
TeamsEl := UIA.ElementFromHandle(WinId)
If !TeamsEl.FindFirstBy("AutomationId=idna-me-control-set-status-message-trigger") { ; menu not opened
; Click on avatar
MeCtrl := TeamsEl.FindFirstBy("AutomationId=idna-me-control-avatar-trigger")
MeCtrl.Click()
El:= TeamsEl.WaitElementExistByNameAndType("Switch to " . sTenant,"MenuItem",,1,False,1000)
} Else { ; menu already opened
El:= TeamsEl.FindFirstByNameAndType("Switch to " . sTenant,"MenuItem",,1,False)
}
If (El="") {
TrayTipAutoHide("Switch Tenant","Tenant name starting with '" . sTenant . "' not found!")
} Else
El.Click()
} ; eofun

Teamsy usage


Use the "sw" keyword followed by the Tenant name (partial match, starting letters), match is case insensitive.

Pretty easy.