How to read a value in a plist file for an extension attribute

howie_isaacks
Valued Contributor II

The built-in Apple software update payload that we can use in a policy will save a plist file to /Library/Application Support/JAMF called .userdelay.plist. The presence of this plist means that the user has selected one of the deferral options. It was easy to create an extension attribute that checks the file path above for the plist file, but what I would also like to do is track how long of a deferral the user selected. The text of the plist file is below. What I would like to do is make an extension attribute that will report the value for the key called "lastChosenDeferDate". 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>140</key>
	<dict>
		<key>deferStartDate</key>
		<date>2021-08-11T14:08:46Z</date>
		<key>lastChosenDeferDate</key>
		<date>2021-08-13T14:08:46Z</date>
	</dict>
</dict>
</plist>

 I thought this would basically be the same as the command we would use to find the version of an app installed, which is to get the value of the CFBundleShortVersionString key in info.plist. That command won't work on the userdelay.plist file. Does anyone know how I can get what I need for my extension attribute?

1 ACCEPTED SOLUTION

vinu_thankachan
Contributor

lastChosenDeferDate is a nested Plist value 

Better to use plistbuddy 

/usr/libexec/PlistBuddy -c 'print ":140:lastChosenDeferDate"'  <path to the plist file >

 

View solution in original post

5 REPLIES 5

vinu_thankachan
Contributor

lastChosenDeferDate is a nested Plist value 

Better to use plistbuddy 

/usr/libexec/PlistBuddy -c 'print ":140:lastChosenDeferDate"'  <path to the plist file >

 

This worked great. Thank you! I was doing it wrong and I didn't think about the fact that the key I wanted to focus on is nested. The plist file gets created whether or not the user defers the policy, so if they don't defer it, the key won't be present. So when my EA echos the results of what I call deferredTime, the result is totally blank. So, my question now is how do we create a result for an extension attribute to display if the key does not exist? When I first started this I had the assumption that the plist doesn't get created unless the user defers updates. Maybe my I need an elif command to check if the key is present in the plist.

howie_isaacks
Valued Contributor II

I will try that. Thanks 😊 

I was trying to use PlistBuddy but I wasn’t doing it right. 

Paige
New Contributor

I'm interested in extracting the <string>GLX_DUD</string> to build a smart group from that string to create an extension attribute.

McDVOICE

Ralph987
New Contributor

Thanks for sharing information this is useful.

 

sky light pay card