Skip to main content
Question

How to use python in Extension Attribute scripts


Forum|alt.badge.img+6

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!

6 replies

Forum|alt.badge.img+16
  • Legendary Contributor
  • 7880 replies
  • May 5, 2021

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

Forum|alt.badge.img+6
  • Author
  • Contributor
  • 23 replies
  • May 5, 2021

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"


Forum|alt.badge.img+16
  • Legendary Contributor
  • 7880 replies
  • May 5, 2021

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.


Forum|alt.badge.img+6
  • Author
  • Contributor
  • 23 replies
  • May 5, 2021

That appears to have worked. thank you


Forum|alt.badge.img+31
  • Honored Contributor
  • 2721 replies
  • May 9, 2021

you might have to open the file to read it in python


Forum|alt.badge.img+31
  • Honored Contributor
  • 2721 replies
  • May 10, 2021

example:

with open('/Library/Preferences/com.apple.SoftwareUpdate.plist', 'rb') as f:
     data = plistlib.load(f)
     print(data)

Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings