How to wait for desktop to be ready?

bearzooka
Contributor

Probably this has been asked before, but the combination of keywords keeps pointing me to other topics.

Is there a way to wait for the desktop to be ready once the user logs in? Or, in other words, a way to delay a log in policy script long enough so it executes when the user has seen his desktop, dock and so on?

Currently I'm only using a sleep command, but the time I put there doesn't necessarily match the time it takes for the session to start and the desktop to show up.

Thanks!

6 REPLIES 6

mm2270
Legendary Contributor III

If it's a script you're talking about, you could put a loop in the beginning of the script that keeps checking for the Dock to be running, since once the Desktop loads, the Dock process should also be there. Continue to loop, checking for the Dock after a brief sleep command, until it sees it, then exit the loop and continue with the rest of the script.

For some sanity and not having a script run indefinitely, you'll probably want to include a counter to increment, so the script will gracefully time out if the Dock is never seen for some reason.

bearzooka
Contributor

That's the kind of idea I was looking for: what process could be a reliable flag that the session is started?

Thanks, @mm2270, I'll try that out.

dpertschi
Valued Contributor

@bearzooka I'm doing that with a DEP workflow and it works well.
I borrowed the top section of code from here.

Put that in a before script, at the very beginning of your policy, and it will loop until the Dock loads. Then the balance of the policy runs.

I like it, thanks Bryan!

bearzooka
Contributor

Thanks @dpertschi, that reference helped me as well.

Look
Valued Contributor III

I have been using an if statement to determine if the machine was ready to mount network shares.
I have used CoreLocationAgent as it's one of the later things to launch in 10.13 but I have adjusted it every year to whatever process appears well down the list on the current macOS from the below command.

ps -c -u $USER -o "etime command"

For support of older systems it eventually times out at 60 seconds and if the Finder is running at that point assumes it's all okay, it's intended to be used as such if used in a Casper script, otherwise you need another way to determine Current_User.

User_Ready() {
Loop_End=$((SECONDS + 60))
while [[ -z "$(ps -c -u $Current_User | awk /CoreLocationAgent/)" ]] && [[ $SECONDS -lt $Loop_End ]]; do
sleep 3
done
if [[ "$(ps -c -u $Current_User | awk /Finder/)" ]]; then
logger "User check PASS"
return 0
else
logger "User check FAIL"
return 1
fi
}

Current_User=$3
if User_Ready then;
PERFORM SOME ACTION
fi

gachowski
Valued Contributor II

Some other possibilities ..

https://www.jamf.com/jamf-nation/discussions/26183/dep-enrollment-confirming-user-is-fully-logged-in

https://www.jamf.com/jamf-nation/discussions/26254/zero-touch-dep-pausing-policies-that-run-on-enrollment-complete-until-setup