Took me awhile to discover this and could not find a solution anywhere in Jamf Nation so thought I would post my solution I used. I have several Extension Attribute scripts that require a user to be logged in (including 2 provided by Jamf Onboarding, Jamf Connect First Run and Entra Registration statuses). Problem is if Inventory Update runs when no user is logged in (yes, this happens) the script does not detect current user so it cannot access current user folder to check plist file so it updates the EA to Not Found losing the Entra Registration completed or Jamf Connect First Run Completed (or any other EA that uses user directory).
I created a script to detect if user logged in and if not to use a cached status created/updated from previous run when a user was logged in. Hopefully this helps someone else or someone else has an improvement to it:
#!/bin/bash
# 1. CREATE EA CACHE
# Set this to match your EA name exactly (avoid spaces if possible)
EA_NAME="EA_Name"
# Create a dedicated hidden directory for EA caches
cacheDir="/Library/Application Support/JAMF/EA_Caches"
mkdir -p "$cacheDir"
cacheFile="$cacheDir/.last_value_$EA_NAME"
# 2. LOGGED-IN USER CHECK
currentUser=$(scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ && ! /loginwindow/ { print $3 }')
if [[ -z "$currentUser" || "$currentUser" == "root" ]]; then
# NO USER: Return cached value to prevent blank or incorrect value
if [[ -f "$cacheFile" ]]; then
echo "<result>$(cat "$cacheFile")</result>"
else
# If no cache exists yet, you can choose to exit 0 (blank) or set a placeholder
echo "<result>Waiting for Login</result>"
fi
exit 0
fi
# 3. RUN YOUR EA SCRIPT HERE - use currentResult variable for result data
# 4. UPDATE CACHE AND REPORT TO JAMF
echo "$currentResult" > "$cacheFile"
echo "<result>$currentResult</result>"
