Skip to content

Instantly share code, notes, and snippets.

@chrisgrande
Created January 8, 2024 22:55
Show Gist options
  • Save chrisgrande/b9e3498077952915cf0250e7a0e9cc8e to your computer and use it in GitHub Desktop.
Save chrisgrande/b9e3498077952915cf0250e7a0e9cc8e to your computer and use it in GitHub Desktop.
macOS Software Update DDM Extension Attribute
#!/bin/bash
# Define the path to the property list file
plist_file="/var/db/softwareupdate/SoftwareUpdateDDMStatePersistence.plist"
# Check if the file exists
if [ -f "$plist_file" ]; then
# Use PlistBuddy to extract the Declarations section
declarations=$(/usr/libexec/PlistBuddy -c "Print SUCorePersistedStatePolicyFields:Declarations" "$plist_file")
# Extract the values
target_os=$(echo "$declarations" | grep -o 'TargetOSVersion = [^ ]*' | cut -d' ' -f3)
target_build=$(echo "$declarations" | grep -o 'TargetBuildVersion = [^ ]*' | cut -d' ' -f3)
iso_datetime=$(echo "$declarations" | grep -o 'TargetLocalDateTime = [^ ]*' | cut -d' ' -f3)
# Convert ISO date and time to the desired format
formatted_datetime=$(date -j -f "%Y-%m-%dT%H:%M:%S" "$iso_datetime" "+%A, %B %d, %Y %I:%M%p")
# Create the formatted string
formatted_string="Target OS: $target_os ($target_build), Install Date: $formatted_datetime"
# Print the result
echo "<result>$formatted_string</result>"
else
# File does not exist, return an error message
echo "<result>Error: File not found</result>"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment