I've been banging my head against the wall with this one. What I'd like to happen is, after DEP enrollment, and we get to the desktop, an AppleScript dialog pops up asking the user a question. There are a few popups, but for troubleshooting purposes, let's just go with the first one. I understand the underlying issue is calling osascript from root. Hoping fresh eyes might see what's wrong or provide some further insight?
#!/bin/sh
# Wait until user is fully logged in & get user
dockStatus=$(pgrep -x Dock)
until [[ "$dockStatus" != "" ]]; do
echo "Waiting for login to complete..."
sleep 2
dockStatus=$(pgrep -x Dock)
done
LoggedInUser=$(python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
");' )
LoggedInUserPID=$(ps auxww | grep "/System/Library/CoreServices/loginwindow.app/Contents/MacOS/loginwindow" | grep $LoggedInUser | grep -v "grep" | awk '{print $2}')
# Ask if we want to run Setup now
Setup=$(sudo -u "$LoggedInUser" osascript << EOF
set theDialogText to "Thank you for enrolling this computer.
Run Setup now to configure your computer.
"
display dialog theDialogText with icon file "Macintosh HD:Library:Images:Setup.png" with title "Enrollment Complete" buttons {"Run Setup","Not Now"} default button 1
EOF
)
So I've tried the above, and also using the PID and launchctl:
# Ask if we want to run Setup now
Setup=$(/bin/launchctl asuser $LoggedInUserPID osascript << EOF
set theDialogText to "Thank you for enrolling this computer.
Run Setup now to configure your computer.
"
display dialog theDialogText with icon file "Macintosh HD:Library:Images:Setup.png" with title "Enrollment Complete" buttons {"Run Setup","Not Now"} default button 1
EOF
)
Using sudo -u gets me "execution error: No user interaction allowed. (-1713)"
Using launchctl asuser gets me "osascript[5156:34547] -[__NSCFConstantString objectAtIndex:]: unrecognized selector sent to instance 0x7fff8f328590", and a "first throw call stack", ending with "libc++abi.dylib: terminating with uncaught exception of type NSException".
Neither prompt the user.
Help?
NOTE: I'm using osascript as opposed to JamfHelper because the second pop-up asks for textbox input.
