Over the past few months, I've found a new use for the pictures that I've taken while hiking. I started using them as Zoom virtual backgrounds.
If you are anything like me and take a lot of pictures, it can be hard to decide which one looks good. And then I decided to use them all, on different days.
Sadly, Zoom does not have this as a built-in feature. So being a Software developer, I had to automate the process of choosing a random Zoom virtual background every day.
What does the script do?
Zoom does have an API that I could have used to change my background every day – but that seemed like too much effort for this task. Software developers are born lazy, right? :)
Instead, I found out that the Zoom application creates a copy of the background that gets selected in its preferences folder and references it. The script just takes in a random file and replaces it with this background file. And voila! A different Zoom virtual background is shown.
You can then put this in a cron job to be executed every day (or any frequency you prefer) to periodically change the background.
Get Set Up
I have put all the images I want to use as backgrounds in a folder in my user directory. Mine is at
/zoom/bgpictures/, and that is what I use in the script. But it is a variable that you can change to whatever you want it to be.
Next, we set a Zoom virtual background in our application. It does not matter which background you choose. All we need is the unique ID that Zoom will assign to this background.
There might be some files already in the directory, but we want to select the one that corresponds to the image that we just uploaded to avoid replacing a different file.
The directory is located at:
~/Library/Application Support/zoom.us/data/VirtualBkgnd_Custom. The file name will be something like:
How to Write the Script
We will be using a bash script to replace the image we just used. I will be putting this scrip in the Zoom folder that I created for the background images. Again, it can be named whatever you like – I am naming mine
The script is as follows:
#!/bin/bash # The name of file that we copied before and will be replaced with OG_BG="9WAE197F-90G2-4EL2-9M1F-AP784B4C2FAD"; # Directory where Zoom keeps the backgrounds ZOOM_DIR="/Users/$USER/Library/Application Support/zoom.us/data/VirtualBkgnd_Custom/"; # Directory of our images BGPATH="/Users/$USER/zoom/bgpictures/"; # Picking a random file NEW_BG=$(find "$BGPATH" -type f | sort -R | head -1); # Replacing the file cp -R "$NEW_BG" "$ZOOM_DIR/$OG_BG";
If you choose different paths for the directory, just make sure to change that in the variable. We need to make this script executable by running the command:
chmod 755 ~/zoom/zoombg.sh
How to Change Your Zoom Background Randomly
The script is ready. All we need to do is put it in a cron job which is a built-in time-based job scheduler. We need to decide a schedule for how frequently we want to change the Zoom virtual background. I do mine at 9:55 AM every day since my meetings start at 10 AM.
If you are new to cron jobs, you can use the generator to help you. I use:
55 9 * * 1-5 /Users/saranshkataria/zoom/zoombg.sh > /dev/null 2>&1
The first part (55 9 * * 1–5) is what you will need to customize according to your schedule. The second part is just telling the OS what to do at that point in time. You'll need to update the path if you chose a different location for the bash script.
To put it in a cron job, type:
and it will open up an editor using vi. Hit the I key on the keyboard to enter insert mode, paste in the line, and press Escape followed by “:wq” and enter to save and quit.
That is all there is to it! Now you'll have a random Zoom virtual background every day (or however often you choose).
If you are using Windows, you can modify the script accordingly and it should be fairly straightforward to use.
If you have any questions, feel free to reach out to me.
Read more of my posts at: https://www.wisdomgeek.com