Hi All,
Hoping someone has already solved this problem and is willing to share! I'm reworking a great python script from @glee_edin (thanks!) (GitHub link) and need to run osascript as the logged in user. I've never done anything in python before, so I'm coming up a little short. I've got the function looking like this so far: (ignore the bad quoting - the forum isn't parsing it correctly)
#!/usr/bin/python
def user_wants_to_defer(defer_until, updates):
answer = """
osascript -e '
tell application "System Events"
with timeout of 8947878 seconds
set result to (display dialog "The following updates are available and require a restart:
%s
You can choose to restart and install them now, or delay until: %s
Updates will automatically be installed at that time if they haven't already been installed." with title "Required macOS Updates Available" with icon ("path/to/icon.icns" as POSIX file) buttons {"Restart Later", "Restart Now"} default button "Restart Now")
end timeout
end tell
if button returned of result = "Restart Later" then
return "2"
else
return "0"
end if
'
""" % (updates, defer_until.strftime("%H:%M on %a, %d %b"))
in bash I'd just do this:
#!/bin/sh
su - "${loggedInUser}" -c osascript -e <<EOT
do stuff here
EOT
Anybody know of something similar? Hopefully this makes sense... :)
Thanks!
att