Hi Chris,
What we do is trigger a policy from "enrollment complete" that runs a script that checks the current UID and loops until it's a 501 (or 502 in our specific case) and THEN move on to a loop that waits for the dock to load. At that point we start the naming/binding/everything else.
Here's some snippets of the scripts we use:
"Waiting for user to finish logging in" Script:
#!/bin/bash
# Function to add date to log entries
log(){
NOW="$(date +"*%Y-%m-%d %H:%M:%S")"
echo "$NOW": "$1"
}
# Logging for troubleshooting - view the log at /var/log/prefirstrun.log
touch /var/log/prefirstrun.log
exec 2>&1>/var/log/prefirstrun.log
# Disable Software Updates during imaging
softwareupdate --schedule off
log "Software Updates disabled"
# Get the currently logged in user
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 + "
");'`
log "Current user is $loggedInUser"
# get UID for current User
currentUID=$(dscl . -list /Users UniqueID | grep $loggedInUser | awk '{print $2;}')
log "$loggedInUser UID is $currentUID"
# Check and see if we're currently running as the user we want to setup - pause and wait if not
while [ $currentUID -ne 502 ] && [ $currentUID -ne 501 ]; do
log "Currently logged in user is NOT the 501 or 502 user. Waiting."
sleep 5
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 + "
");'`
currentUID=$(dscl . -list /Users UniqueID | grep $loggedInUser | awk '{print $2;}')
log "Current user is $loggedInUser with UID $currentUID"
done
# Now that we have the correct user logged in - need to wait for the login to complete so we don't start too early
dockStatus=$(pgrep -x Dock)
log "Waiting for Desktop"
while [ "$dockStatus" == "" ]; do
log "Desktop is not loaded. Waiting."
sleep 5
dockStatus=$(pgrep -x Dock)
done
# Start the imaging process since we're now running as the correct user.
log "501 or 502 user is now logged in, continuing setup."
jamf policy -event firstRun
exit 0
Prompt for naming script:
#!/bin/sh
# Prompt user to name computer
computerNamePrompt(){
# $1 = window title
# $2 = prompt text
# $3 = default answer
su - "${loggedInUser}" -c osascript <<EOT
tell application "System Events"
with timeout of 8947848 seconds
text returned of (display dialog "$2" default answer "$3" buttons {"OK"} default button 1 with title "$1" with icon ("path/to/icon.icns" as POSIX file))
end timeout
end tell
EOT
}
# Ask for Computer name to use when binding
log "Prompting user to enter computer name"
computerName="$(computerNamePrompt 'Enter Computer Name' 'Please enter a Computer Name following the companyname standard.
Example: computernamestandard' 'genericizedcomputername')"
log "User entered $computerName"
Hopefully this will get ya started. This took a lot of playing around with to get a good solution! It seems Apple has changed things fairly recently and now DEP isn't triggering as early as it used to - we would have so many policies run as "_mbsetupuser" which just didn't work for us. The looping scripts did the trick and allow the Jamf policies to start at a more reasonable time.
Good luck!
Matt