I've been using an app called artpip for a while, it's great: https://www.artpip.com/
Also @OP - you might want to take a look at the wallpaper-macos[0] lib that I developed for Artpip. It uses the nodobj node wrapper but it should be a useful reference. You don't need to read from the sqlite DB or deal with restarting the dock. You can reliably get the current wallpaper like so [1]. Also you might want to check out how [2] it handles setting backgrounds on multiple spaces, should you want to support that.
[0] https://github.com/tom-james-watson/wallpaper-macos
[1] https://github.com/tom-james-watson/wallpaper-macos/blob/mas...