Want to make sure that the green checkmark next to your image on Skype or Teams, signaling your availability to your co-workers, stays on?
Kidding — Keep reading and find a full instruction for an automation in this post. All you need to do is:
- Download python
- Import a few packages
- Copy and execute script
- Take a nice break away from the screen while staying online
How can you make sure to remain online constantly even through a coffee break or post-lunch walk ? Inspired by “Automate the boring stuff with python”,
this script is ridiculously short and effective, and ANYONE can implement it to stay online!
How does Teams or Skype recognize that you are inactive? Once there is no mouse movement, typing or click action going on for several minutes, you will be marked as absent. So all we have to do is keep the laptop going while you’re off, using the graphical user interface automation package pyautogui.
1. Download python
Skip to step 2 if you are already using python, otherwise, visit python.org and download a stable version, I recommend 3.8. Unzip and install the download.
2. Import a few packages
Hit the Terminal application on your mac. On windows, press the windows icon + r and type “cmd”. This will navigate you to the command prompt. Then, install the necessary packages using the following lines.
pip install pyautogui
pip install time
3. Copy and run script
Now if you don’t care about how the automation works, you have several options to skip right to the execution of the script.
On a mac, you can type the following command into your terminal, to set the directory to Downloads. Make sure that in the next step, you download the script in the following section, so that it is indeed located in the Downloads folder. Assuming the .py file is called “working.py”, you can simply execute it like this.
cd ~/Downloads#this line will execute the script
Alternatively you can open the python built-in editor by typing “idle” into your command prompt. Go ahead and paste script into a new file, which you can create using the top bar. Once it’s pasted in, hit F5 or click Run and you’ll stay online for as long as your computer has charge.
In any case, you will have to give automation permission to the editor you are using, by adjusting your system preferences. As an example, I tried running it in Visual Studio Code.
You can give permission by checking the editor or environment you are using.
When you move the mouse yourself while executing the script, a pop-up will ask you whether you are still woking.
If you want the program to continue, press “OK”. You can exit the program anytime by moving your mouse and selecting “Cancel”, or by x-ing away the pop-up window. I recommend you to collapse your open windows into the task bar, and let this program run on an empty desktop, without any application icons in the background.
For those interested, let’s dive into the details so that you can customize this program as you wish!
In the beginning, we move the mouse to an arbitrary position. I have selected a central position, as the FailSafeException might be raised when you hit the boundaries of your computer. As the name suggests, that’s a pyautogui function which makes sure that a user will eventually be able to gain back control in case the automation goes wrong. However, this program was safely tested by myself so you can go ahead and place it into the expected exceptions.
Anyways, after we set the position, we fetch the width and the height in the variables w and h. n is a random hardcoded integer.
#set mouse and n
w, h = pyautogui.position()
n = 120
Now the base loop will continue while our integer n = 120, which is essentially always true. We call the positionmove() function, which will in turn check the position of the mouse. If the mouse position hasn’t changed, meaning you aren’t doing anything and the mouse is still at (917, 430), it’ll go on to simulate movement. The moving() function alters the cursor for 5 seconds, then relocate it to (917, 430) and simulates a double-click. During these 5 seconds of simulation, you can’t interrupt the processes. However, you can adjust the direction or the length of the move. Pyautogui offers amazing functions, so you can try it out and use any other feature that simulates you being at work. It is essential to relocate the cursor after your automation, as this script is entirely based on the cursor position (917, 430).
#infinite base loop
while n == 120:
a = positionmove()
n = a
n = wait()
n = 120
Now if the positioncheck() actually fetched a width that is not equal to 917, meaning you have moved your cursor, it’ll raise the call() function, which will trigger the pop-up window. You can go on and reply to a chat message or an email, then return to the pop-up window to click “OK” and enter the base loop again. Otherwise, n = 100 is returned by the call() funtion, which will exit the loop.
So if the positionmove() triggers the simulation smoothly, n=120 is returned to the base loop, and we continue to iterate over the wait() and positionmove() function. This is the natural state of the program, where the mouse position will constantly be checked, and it stays alert to raise the call() function in case you wish to exit. Otherwise, it will count and sleep for 5 seconds in total, while keeping the mouse at (917, 430)
And that’s it! My pro tip is to turn down the screen-brightness and close running applications except for Teams or Skype, to save energy .