4

I'd like my Microsoft Teams status to automatically be set to Be Right Back when I lock my PC and to Available when I unlock my PC. Is this possible?

I have:

  1. Looked into whether there are any relevant CLI switches / options that I can plug in to by Googling it, running teams.exe -? and teams.exe /?, and running Strings on teams.exe but it seems that there is not.

  2. Used Process Monitor / procmon to trace the activity when statuses are changed but found nothing useful. The only notable thing I found was the following entry in the file %appData%\Microsoft\Teams\logs.txt but it didn't lead me to anything useful:

    Fri Jul 03 2020 13:23:17 GMT+0100 (British Summer Time) <3292> -- event -- panelaction: Action.Outcome: setpresence, DataBag.PresenceState: beRightBack, Action.Gesture: click, Action.Scenario: setPresenceFromTrayMenu, Action.ScenarioType: other, ppChannel: Production::CC, distSrc: PROPLUS_O365BusinessRetail, ppInstallMode: UPDATE, autoStartPolicy: undefined, vdiMode: 0, eventpdclevel: 2, 
    
  3. Looked into using an AutoHotkey mouse macro but I haven't really pursued this because I'm hoping for a better solution, I'm unsure whether it'd work on lock and unlock, and it's a bit tricky because the statuses are only accessible by hovering over the System Tray or in-app context menu item first.

3 Answers3

1

When locking and unlocking my Windows session, Teams takes a second or two to update its icon and, in that time, I've noticed that it automatically sets its status to away and back which is good enough for me.

enter image description here

If anyone else manages to come up with a way of programmatically controlling Teams statuses then I'll change the accepted answer to theirs.

0

Note: If you have the ability to register an Azure connected app with your organization (and receive a client ID/client secret), see Đrakenus's answer, which would be more appropriate.

I've created something that works for me, but it's a hack, so please forgive me in advance. Desperate times call for desperate measures...

I used Java's java.awt.Robot to manually click the status to be changed in Teams.

Here's an example:

import java.awt.*;
import java.awt.event.InputEvent;
import java.io.IOException;

public class StatusChanger {

private static final int waitBetweenSteps = 300;
private static Robot robot;

public static void main(String[] args) throws IOException, InterruptedException, AWTException {
    robot = new Robot();

    // Get the status from the first arg to the program, options are
    // away, available, busy, or offline.
    final String status = args[0];

    // This will bring the Teams window into focus on macOS, there is likely
    // a similar solution for Windows.
    runCommand(new String[]{&quot;osascript&quot;, &quot;-e&quot;, &quot;tell application \&quot;System Events\&quot; to tell process \&quot;Microsoft Teams\&quot; to set frontmost to true&quot;});

    // Move mouse to the profile icon in the top left of the Teams window 
    // and click the icon.
    mouseMove(3760, 50);
    click();

    // Move to the status in the modal that appears and click the status.
    mouseMove(3570, 140);
    click();

    // Move the mouse to the correct status position based on the argument.
    switch (status) {
        case &quot;away&quot;:
            mouseMove(3600, 315);
            break;
        case &quot;busy&quot;:
            mouseMove(3600, 220);
            break;
        case &quot;available&quot;:
            mouseMove(3600, 180);
            break;
        case &quot;offline&quot;:
            mouseMove(3600, 360);
            break;
    }
    // Click the new status.
    click();
    System.out.println(&quot;Status was set to &quot; + status);
}

private static void runCommand(String[] command) throws IOException, InterruptedException {
    Runtime runtime = Runtime.getRuntime();
    Process process = runtime.exec(command);
    process.waitFor();
    Thread.sleep(waitBetweenSteps);
}

private static void click() throws InterruptedException {
    robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
    Thread.sleep(waitBetweenSteps);
}

private static void mouseMove(int x, int y) throws InterruptedException {
    robot.mouseMove(x, y);
    Thread.sleep(waitBetweenSteps);
}

}

Then I build this into a jar (you could also just compile the class with javac) and run the command like:

# Set status to Away
java -jar TeamsStatusChanger.jar away

Set status to Busy

java -jar TeamsStatusChanger.jar busy

Set status to Available

java -jar TeamsStatusChanger.jar away

Set status to Offline

java -jar TeamsStatusChanger.jar offline

You can then use cron to set your status automatically during specific timeframes:

# set Teams status to offline at 5pm
0 17 * * * java -jar /path/to/TeamsStatusChanger.jar offline

There are a few caveats:

  • It requires you to keep Teams running, but could certainly be improved to check if Teams is running and start it/wait if it's not.
  • It requires you to keep your Teams window in the same position (in my case, the top-right of the screen against the monitor's edge).
  • The coordinates for this utility are hard-coded for my monitor size, which is 3840x1600. You will need to update the mouseMove calls with the proper coordinates of each "click" area (see next point).
  • On macOS, you can use the screenshot tool to find the coordinates of each "click" area on your own monitor by pressing Cmd+Shift+4 and hovering over the area you want to click. The screen coordinates will be shown next to the crosshair.
  • I'm not sure what this will do if you're using multiple monitors, it might require some additional tweaking or only work on your main monitor.
blacktide
  • 101
  • 2
0

There is a way to programmatically set a MS Teams status, see https://docs.microsoft.com/en-us/graph/api/presence-setpresence?view=graph-rest-beta&tabs=http

You can also combine it with Microsoft Teams Powershell module, there is a Connect-Teams cmdlet, see here - https://docs.microsoft.com/en-us/powershell/module/teams/connect-microsoftteams?view=teams-ps

However this might need additional setup -- you will probably need an Microsoft Graph API access via an Azure application (see https://docs.microsoft.com/en-us/powershell/module/teams/connect-microsoftteams?view=teams-ps#parameters), section about -AccessTokens parameter.

Đrakenus
  • 101