ah, looks like I fixed it after having a good read of
https://scriptingosx.com/2020/08/running-a-command-as-another-user/
again and using:launchctl asuser "$uid" sudo -u "$loggedInUser".... That
does the trick and the policy runs successfully.
Did you ever find a solution? I'm facing the same problem:I'm trying to
deploy some Microsoft Remote Desktop bookmarks for our users, which I'm
fairly certain I did in the past without much hassle using the built in
--script command: ... sudo -u $log...