November 17, 2020

Teams Shortcuts: Personalize Mentions

Mentions in Microsoft Teams are not very personalized. (This does not fit to a #callmebymyfirstname #gernperdu culture.)

In this post I explain how to personalize Microsoft Teams mentions the manual way and the powerful way using Teams Shortcuts Powertool. (AutoHotkey can "du" it)

Screencast

Manual way

Mentions with Lastname, Firstname format

  • Ctrl+Left Arrow (to jump before the previous word=Firstname)
  • Backspace (delete Lastname,)

Mentions with Lastname, Firstname (Uid)

  • {Backspace} (delete (uid))
  • Ctrl+Left Arrow (to jump before previous word=Firstname)
  • {Backspace} (delete word before = Lastname,)
Removing numbers from Firstname seems not possible: it will break the mention formatting.

Teams Shortcuts

Usage

You shall run the mention personalization right after inserting a mention (the cursor must be just after the mention.)
You can run it with the hotkey Win+1 or also from Teams Shortcuts main menu that you can open in Teams with the hotkey Win+T:


(menu might change along with tool development)

Main code

Main code is implemented in ahk/Lib/Teams.ahk-> Teams_PersonalizeMention function. 
Extract below:
Teams_PersonalizeMention() {
SendInput +{Left}
sLastLetter := GetSelection("html")
IsRealMention := InStr(sLastLetter,"http://schema.skype.com/Mention") 
sLastLetter := GetSelection()    
SendInput {Right}

If (IsRealMention) {
    If (sLastLetter = ")")
        SendInput {Backspace}^{Left}{Backspace}
    Else 
        SendInput ^{Left}{Backspace}
} 
};eofun

The function checks if it is a real mention by getting the last character first in Html format and looks it the string http://schema.skype.com/Mention is contained.
If the mention is not autocompleted it won't be the case.
In this case as well the personalization is skipped because it won't be clear which user would be intended if only the firstname in plain text is readable.

Implementation notes

Failed prototypes

Transforming and pasting HTML code for mention

Note: I have tried first the approach with pasting HTML code but it does not work.
(Most likely because you can't copy/ paste mentions as well.)

PersonalizeMentions:
; Does not work!
Send ^a
sHtml := GetSelection("html")
sPat = Us)<span .* itemtype="http://schema.skype.com/Mention".*>(.*)</span>
sNewHtml := sHtml
Pos = 1 
While Pos := RegExMatch(sHtml,sPat,sFullName,Pos+StrLen(sFullName)){
    sFullName1 := RegExReplace(sFullName1," (.*)","")
    FirstName := RegExReplace(sFullName1,".*, ","")
    sNewHtml := StrReplace(sNewHtml,sFullName1,FirstName)
}
;sNewHtml := RegExReplace(sNewHtml,"s).*<html>","<html>")
WinClip.SetHTML(sNewHtml)
WinClip.Paste()

return

Removing numbers in Firstname

Here is the code that would remove the numbers in the firstname. Unfortunately it also breaks the mention.
It simply selects the last letter of the firstname and check if it is a digit/ number. If so it will delete the selection. It does this twice because most likely two digits are the max.
SendInput +{Left}
sLastLetter := GetSelection()
If RegExMatch(sLastLetter,"\d")
    SendInput {Delete}
SendInput +{Left}
sLastLetter := GetSelection()
If RegExMatch(sLastLetter,"\d")
    SendInput {Delete}
SendInput {Right}

See also

Teams Shortcuts Homepage

Teams shortcuts: send mention

No comments:

Post a Comment