Skip to content

Instantly share code, notes, and snippets.

@spokanemac
Created November 6, 2024 00:37
Show Gist options
  • Save spokanemac/176e874961a26abcb2d19a77dd82f5fd to your computer and use it in GitHub Desktop.
Save spokanemac/176e874961a26abcb2d19a77dd82f5fd to your computer and use it in GitHub Desktop.
If Apple Care is active, there may be a file in the primary Users Library folder.
#!/bin/sh
### If Apple Care is active, there may be a file in the primary Users Library folder.
### Get the current user's username and home folder location
loggedInUser=$(ls -l /dev/console | awk '{ print $3 }')
myUserHome=$(dscl . read /Users/$loggedInUser NFSHomeDirectory | awk '{print $NF}')
echo "The logged in user is $loggedInUser"
### Check if the Warranty file exists
warrantyDir="/Users/$loggedInUser/Library/Application Support/com.apple.NewDeviceOutreach/"
if [ ! -d "$warrantyDir" ]; then
echo "No Warranty Directory"
exit 1
fi
cd "$warrantyDir" || exit 1
warrantyFiles=(*_Warranty)
# Loop to look at each file one at a time and stop if condition is true
for i in "${warrantyFiles[@]}"
do
echo "$i"
### Get the warranty expiration date in epoch seconds.
expires=$(defaults read "$warrantyDir/$i" coverageEndDate 2>/dev/null)
if [ -z "$expires" ]; then
echo "File has no expiration date – skipping this file."
else
### Convert epoch to a standard date format
APCexpires=$(date -j -f '%s' "$expires" +%b\ %d,\ %Y)
echo "$APCexpires"
exit 0
fi
done
echo "No Warranty File"
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment