GNOME Lock Screen From Command Line/Bash Script

I’m attempting to make a new top bar for my system (Pop OS 22.04) using polybar. I have it all mostly working, and am attempting to make a power menu. I have the logout, power and restart buttons all working, but am struggling on the lock button.

I have a label with the left-click action set a bash script. I have confirmed that the script is getting executed as if I have script launch Firefox it does. The problem is that that I have not been able to find a working command. I have tried

gnome-screensaver-command --lock

xdg-screensaver lock

dbus-send --type=method_call --dest=org.gnome.ScreenSaver/org/gnome/ScreenSaver org.gnome.ScreenSaver.Lock

They all work when run in the terminal, but not in a bash script. I think it may have somthing to do with polybar running them as root, so I tried running them as my user, but that did not solve it.

Is there some command that locks the screen of a specified user/desktop environment?

Thanks. Just comment if any more info is needed.

All of the commands mentioned where taken from answers from this question.