Hey everyone -
I'm a bit of a newbie with coding, and seem to be running into the issue where my apple script in my script is being called as root from my jamf policy instead of as the logged in user, which is causing a whole mess of issues. I'm attempting to use Popen to switch users with sudo -u, here's my code snippet:
userPopup = <apple script string here>
#get the current logged in user
user = subprocess.Popen("stat -f '%Su' /dev/console", stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
output, error = user.communicate()
accountName = output
accountName = str(accountName).strip()
osa = subprocess.Popen(['sudo', '-u', accountName, 'osascript', '-'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell=True)
buttonReturn = osa.communicate(userPopup)
buttonReturn = str(buttonReturn[0]).strip()
print(buttonReturn)
Any ideas why this isn't working correctly? It's throwing errors about the -u flag, and i'm not 100% sure why. I've verified that the accountName variable is populating with the expected value as well.
Thanks in advance!!