Posted on 05-05-2021 12:12 PM
I am trying to get info from a plist to see if the machine has any updates pending and I got this so far:
But the returned value is not showing up. What am i doing wrong here? Thanks!
Posted on 05-05-2021 12:38 PM
I'm not sure what the issue would be, since from what I can tell it should be outputting the results in between those <result></result> tags. But, why use python for something this simple? A standard shell script using defaults
can do this just as easily.
#!/bin/sh
if [[ $(/usr/bin/defaults read /Library/Preferences/com.apple.SoftwareUpdate.plist RecommendedUpdates 2>/dev/null) == "" ]]; then
/bin/echo "<result>No Updates</result>"
else
/bin/echo "<result>Updates</result>"
fi
Posted on 05-05-2021 12:46 PM
I have tried using defaults but it doesn't return an empty string. It returns a few lines of empty space that I have tried to trim with this
but it still says there are "Updates Needed"
Posted on 05-05-2021 03:11 PM
You could try this:
/usr/bin/defaults read /Library/Preferences/com.apple.SoftwareUpdate.plist RecommendedUpdates | sed 's/)//;s/(//;/^$/d'
That should return a null value if the RecommendedUpdates array is empty or some data if it's not empty. From there the rest of the script should work.
Posted on 05-05-2021 03:41 PM
That appears to have worked. thank you
Posted on 05-08-2021 10:12 PM
you might have to open the file to read it in python
Posted on 05-10-2021 09:14 AM
example:
with open('/Library/Preferences/com.apple.SoftwareUpdate.plist', 'rb') as f:
data = plistlib.load(f)
print(data)