Posted on 03-15-2019 11:20 AM
I'm running into an issue with a Python script where if I run it locally (on any machine) it outputs the correct result. Essentially the script is just looking for the existence of a couple .plist files as of now.
However, when I upload the script into an extension attribute, something goes wrong with getting the current logged in user and messes with the filepath I'm pulling in the script. Any ideas what might be causing this? I'm assuming it must be pulling 'root' as the user when run by jamf or something? Is there a way around this?
Posted on 03-15-2019 12:57 PM
@jrogersnh Post the entire script here using the >_ button. I could easily rewrite this in bash for you to test.
Posted on 03-17-2019 02:34 AM
@jrogersnh this is because of how you are gathering the current user. When EAs run, they are run as root. Using id in the way you are isn’t getting the active console user, it’s getting the username of the person running the command itself. You should use one of the many ways that are listed on here that gather the active console user. You should also make sure you account for when there is no active user logged into the machine as well.
Posted on 03-17-2019 02:38 AM
Since you’re using python, you could use this:
from SystemConfiguration import SCDynamicStoreCopyConsoleUser
username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]
username = [username,""][username in [u"loginwindow", None, u""]]