Last week I had help from @mm2270 to extract our Extension Archive name with given Bundle ID
[https://www.jamf.com/jamf-nation/discussions/24701/find-and-save-value-from-a-plist
](link URL)
I tried to use that script to search for other velues but it was too complicated for me.
There are two values I want to extract from the the Extension.Plist:
- Version = So we could tell which Version the Client use.
- Declined by User = which will tell us if the extension was installed from gallery or in "Developer Mode"
With an attribute extension the IT team of that enterprise can Deploy the software again!
I'm attaching a screenshot
Below there's the code we used to find the extension name and delete it:
#!/bin/bash
## Get logged in user
loggedInUser=$(stat -f%Su /dev/console)
## Build path to the user's Extensions.plist
ExtensionsPlist="/Users/$loggedInUser/Library/Safari/Extensions/Extensions.plist"
## The vendor bundle id for the product
bundleID="com.WalkMe.SafariExtension"
## Get a list of all installed Bundled Identifiers (created as an array)
BundleIdentifiers=($(defaults read "$ExtensionsPlist" | awk -F'"' '/Bundle Identifier/{print $4}'))
## Loop over bundle IDs until we find the one we're looking for, capture the index number
x=0
while read BI; do
if [ "$BI" == "$bundleID" ]; then
index=$x
fi
let x=$((x+1))
done < <(printf '%s
' "${BundleIdentifiers[@]}")
## If we got an index value from the loop...
if [ ! -z "$index" ]; then
## Then get the bundle archive name using PlistBuddy (uses the above captured index number to get the correct dictionary index value)
ArchiveName=$(/usr/libexec/PlistBuddy -c "Print :'Installed Extensions':$index:'Archive File Name'" "$ExtensionsPlist")
## Delete the .safariExtz file using the Archive Name found
rm "/Users/$loggedInUser/Library/Safari/Extensions/$ArchiveName"
else
## If the index was blank, there is nothing installed to delete
echo "No installed product found. Nothing to delete"
fi~[upload](0954e65c23fa494a939de5f6d473cc50)