You can use a terminal command to lock the screen in Mac.
To do that you need to add the following like to your bash_profile (otherwise every time you restart, you'll lose the changes).
A) I don't have bash_profile
Create the file:
Code language: PHP (php)
sudo echo > ~/.bash_profile
B) I have bash_profile
Edit the file (the name might vary depending on that you set the moment you created it):
sudo nano ~/.bash_profile
Add the following line (you can change the "lock" keyword to something else):
alias lock='/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend'
Save the file.