DEV Community

Cover image for Automating MS Teams
Arun krishna
Arun krishna

Posted on • Edited on

Automating MS Teams

My Workflow

Most of us are aware that Teams is a video conferencing app which allows us to attend/conduct meetings. And because of this pandemic situation, the usage of these video conferencing apps also increased and most of the classes and lectures and conferences are conducted in Teams now a days.

Let us see how I have automated Teams so that it automatically logs into one's meetings/classes on time.

  • An infinite loop keeps checking the current time of the system using datetime.now() funtion.
  • The Teams app is opened using os.startfile().
  • pyautogui.locateCenterOnScreen() function locates the center of the first found instance of the image on the screen.
  • pyautogui.moveTo() moves the cursor to that location.
  • pyautogui.click() performs a click operation.

Submission Category:

Wacky Wildcards

Yaml File or Link to Code

GitHub logo Chitturiarunkrishna / msteams

This script allows you to login into your meetings or classes correctly, when time or time interval is provided

Automating MS Teams

forthebadge made-with-python ForTheBadge built-by-Me Generic badge Generic badge Generic badge Generic badge Open Source Love svg1

Most of us are aware that Teams is a video conferencing app which allows us to attend/conduct meetings. And because of this pandemic situation, the usage of these video conferencing apps also increased and most of the classes and lectures and conferences are conducted in Teams now a days.

New Features!

Let us see how I have automated Teams so that it automatically logs into one's meetings/classes on time.

Pre-requisites:

Microsoft Teams application - Download the exe file from official website Python 3.x Pyautogui Intervals

Install Packages:

pip install pyautogui
pip install python-intervals
Enter fullscreen mode Exit fullscreen mode

Execution:

python teams.py
Enter fullscreen mode Exit fullscreen mode

Working (Behind the scenes) :

An infinite loop keeps checking the current time of the system using datetime.now() funtion The Teams app is opened using os.startfile() pyautogui.locateCenterOnScreen() function locates the center of the first found instance of the image on the screen pyautogui.moveTo() moves the cursor to that location pyautogui.click() performs…

Additional Resources / Info

Pre-requisites:

  • Microsoft Teams application - Download the exe file from here
  • Python
  • Pyautogui

Pyautogui :
PyAutoGUI is a cross-platform GUI automation Python module. It programmatically controls the mouse & keyboard. It has screen shot features and also image finding features.

pip install pyautogui
pip install python-intervals
Enter fullscreen mode Exit fullscreen mode

Note :
Before using the script make sure that the Teams application is closed in such a way that all the teams are displayed as shown in the below figure.

Alt Text

Import the necessary modules

import os             
import pyautogui
import intervals as I
import time
from time import sleep
from datetime import datetime
Enter fullscreen mode Exit fullscreen mode

Open Teams

os.startfile("C:/Users/username/AppData/Local/Microsoft/Teams/current/Teams.exe") 
Enter fullscreen mode Exit fullscreen mode

Next, take the screenshot of settings button and use the below chunk of code to move the mouse to that button and click it.

Alt Text

settings = pyautogui.locateCenterOnScreen("settings.PNG") 
pyautogui.moveTo(settings)
pyautogui.click()
time.sleep(2)
Enter fullscreen mode Exit fullscreen mode

Now we need to click on Manage Teams button to get a list of teams vertically.

Alt Text

manageteams = pyautogui.locateCenterOnScreen("manageteams.PNG") 
pyautogui.moveTo(manageteams)
pyautogui.click()
time.sleep(2)
Enter fullscreen mode Exit fullscreen mode

then we will get the screen like this

Alt Text

Now we run the below code snippet in an infintie loop.

We get the current time and compare it with the class ending time . For example if current time is 17:00 and my class is at 17:00 but the meeting has started. If I give my class ending time i.e 18:00 then as soon as meeting starts the scripts automatically clicks on join button with camera and microphone turned off.

  • Join button is given below.

Alt Text

  • Camera and microphone button is given below.

Alt Text

  • Similarily take the screenshot of your class name too.

Alt Text

if now < '18:00':
    Andromeda =pyautogui.locateCenterOnScreen("Andromeda.PNG") 
    pyautogui.moveTo(Andromeda)
    pyautogui.click()
    time.sleep(2)
    join = pyautogui.locateCenterOnScreen("join.PNG") 
    pyautogui.moveTo(join)
    pyautogui.click()
    time.sleep(2)
    audiooff = pyautogui.locateCenterOnScreen("audiooff.PNG") 
    pyautogui.moveTo(audiooff)
    pyautogui.click()
    time.sleep(2)
Enter fullscreen mode Exit fullscreen mode

Similarily you can do it for n number of classes.
In the below code I have done it for 2 classes.

import os             
import pyautogui
import intervals as I
import time
from time import sleep
from datetime import datetime


try:
    # open MS Teams application
    os.startfile("C:/Users/username/AppData/Local/Microsoft/Teams/current/Teams.exe") 
    sleep(2)
    # settings
    settings = pyautogui.locateCenterOnScreen("settings.PNG") 
    pyautogui.moveTo(settings)
    pyautogui.click()
    time.sleep(2)
    # manageteams.PNG
    manageteams = pyautogui.locateCenterOnScreen("manageteams.PNG") 
    pyautogui.moveTo(manageteams)
    pyautogui.click()
    time.sleep(2)
except Exception as e:
    print(e)

while True:
    #andromeda
    now = datetime.now().strftime("%H:%M")
    if now < '18:00':
        Andromeda = pyautogui.locateCenterOnScreen("Andromeda.PNG") 
        pyautogui.moveTo(Andromeda)
        pyautogui.click()
        time.sleep(2)
        join = pyautogui.locateCenterOnScreen("join.PNG") 
        pyautogui.moveTo(join)
        pyautogui.click()
        time.sleep(2)
        audiooff = pyautogui.locateCenterOnScreen("audiooff.PNG") 
        pyautogui.moveTo(audiooff)
        pyautogui.click()
        time.sleep(2)
    elif now <'17:00': 
        Automation = pyautogui.locateCenterOnScreen("Automation.PNG") 
        pyautogui.moveTo(Automation)
        pyautogui.click()
        time.sleep(2)
        join = pyautogui.locateCenterOnScreen("join.PNG") 
        pyautogui.moveTo(join)
        pyautogui.click()
        time.sleep(2)
        audiooff = pyautogui.locateCenterOnScreen("audiooff.PNG") 
        pyautogui.moveTo(audiooff)
        pyautogui.click()
        time.sleep(2)
Enter fullscreen mode Exit fullscreen mode

Suppose if you want to set the time interval and check for meeting to start and then join please see this

while True:
    #andromeda
    k = datetime.now().strftime("%H")
    now = int(k)
    if now in I.closed(16, 17):
        andromeda = pyautogui.locateCenterOnScreen("Andromeda.PNG") 
        pyautogui.moveTo(andromeda)
        pyautogui.click()
        time.sleep(2)
        join = pyautogui.locateCenterOnScreen("join.PNG") 
        pyautogui.moveTo(join)
        pyautogui.click()
        time.sleep(2)
        audiooff = pyautogui.locateCenterOnScreen("audiooff.PNG") 
        pyautogui.moveTo(audiooff)
        pyautogui.click()
        time.sleep(2)
        if now == 17:
            cut = pyautogui.locateCenterOnScreen("cut.PNG") 
            pyautogui.moveTo(cut)
            pyautogui.click()
            time.sleep(2)
            dismiss = pyautogui.locateCenterOnScreen("dismiss.PNG") 
            pyautogui.moveTo(dismiss)
            pyautogui.click()
            time.sleep(2)
            back = pyautogui.locateCenterOnScreen("back.PNG") 
            pyautogui.moveTo(back)
            pyautogui.click()
            time.sleep(2)
Enter fullscreen mode Exit fullscreen mode

Then the entire code will be as below:

import os             
import pyautogui
import intervals as I
import time
from time import sleep
from datetime import datetime


try:
    # open MS Teams application
    os.startfile("C:/Users/username/AppData/Local/Microsoft/Teams/current/Teams.exe") 
    sleep(2)
    # settings
    settings = pyautogui.locateCenterOnScreen("settings.PNG") 
    pyautogui.moveTo(settings)
    pyautogui.click()
    time.sleep(2)
    # manageteams.PNG
    manageteams = pyautogui.locateCenterOnScreen("manageteams.PNG") 
    pyautogui.moveTo(manageteams)
    pyautogui.click()
    time.sleep(2)
except Exception as e:
    print(e)

while True:
    #andromeda
    k = datetime.now().strftime("%H")
    now = int(k)
    if now in I.closed(16, 17):
        andromeda = pyautogui.locateCenterOnScreen("Andromeda.PNG") 
        pyautogui.moveTo(andromeda)
        pyautogui.click()
        time.sleep(2)
        join = pyautogui.locateCenterOnScreen("join.PNG") 
        pyautogui.moveTo(join)
        pyautogui.click()
        time.sleep(2)
        audiooff = pyautogui.locateCenterOnScreen("audiooff.PNG") 
        pyautogui.moveTo(audiooff)
        pyautogui.click()
        time.sleep(2)
        if now == 17:
            cut = pyautogui.locateCenterOnScreen("cut.PNG") 
            pyautogui.moveTo(cut)
            pyautogui.click()
            time.sleep(2)
            dismiss = pyautogui.locateCenterOnScreen("dismiss.PNG") 
            pyautogui.moveTo(dismiss)
            pyautogui.click()
            time.sleep(2)
            back = pyautogui.locateCenterOnScreen("back.PNG") 
            pyautogui.moveTo(back)
            pyautogui.click()
            time.sleep(2)
    elif now in I.closed(17, 18):
        automation = pyautogui.locateCenterOnScreen("automation.PNG") 
        pyautogui.moveTo(automation)
        pyautogui.click()
        time.sleep(2)
        join = pyautogui.locateCenterOnScreen("join.PNG") 
        pyautogui.moveTo(join)
        pyautogui.click()
        time.sleep(2)
        audiooff = pyautogui.locateCenterOnScreen("audiooff.PNG") 
        pyautogui.moveTo(audiooff)
        pyautogui.click()
        time.sleep(2)
        if now == 18:
            cut = pyautogui.locateCenterOnScreen("cut.PNG") 
            pyautogui.moveTo(cut)
            pyautogui.click()
            time.sleep(2)
            dismiss = pyautogui.locateCenterOnScreen("dismiss.PNG") 
            pyautogui.moveTo(dismiss)
            pyautogui.click()
            time.sleep(2)
            back = pyautogui.locateCenterOnScreen("back.PNG") 
            pyautogui.moveTo(back)
            pyautogui.click()
            time.sleep(2)
Enter fullscreen mode Exit fullscreen mode

I have uploaded the entire code and all the required files in my repository. Please drop a star if you like it.

Top comments (0)