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[]{"osascript", "-e", "tell application \"System Events\" to tell process \"Microsoft Teams\" to set frontmost to true"});
// 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 "away":
mouseMove(3600, 315);
break;
case "busy":
mouseMove(3600, 220);
break;
case "available":
mouseMove(3600, 180);
break;
case "offline":
mouseMove(3600, 360);
break;
}
// Click the new status.
click();
System.out.println("Status was set to " + 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.
/available,/awayand/busyswitches. Here's a post with some commands to look over. If you have to do keyboard and mouse strokes, you can likely do that without needing AHK or AutoIT using native commands instead with PowerShell.I don't have access to Teams to test anything though.You can use Event triggers to execute the script accordingly for lock/unlock events too. – Vomit IT - Chunky Mess Style Jul 10 '20 at 15:37