Bash Help required for Extension Attribute

JevermannNG
Contributor III

Hi,

I am trying to find all installed Apps from the Mac App Store which have not been purchased through the VPP/Self Service.

This is what I got with the help of an older Script from Craig Lindsey

#!/bin/bash
    
# JAMF Extension Attribute that finds any MAS apps
# that were NOT purchased through VPP
# Based on Script from: Craig Lindsey for Starz 2017-2-10


checkMD=$(mdfind -onlyin /Applications/ 'kMDItemAppStoreReceiptIsVPPLicensed == "0"')
#echo "### checkMD - $checkMD"

if [ "$checkMD" = "" ]
then
	echo "<result>Not Found</result>"
	exit 0
fi

result=""

mdfind -onlyin /Applications/ 'kMDItemAppStoreReceiptIsVPPLicensed == "0"' | while read VPPApp 
do
	AppName=$( echo "$VPPApp" | awk -F'/' '{print $NF}' | sed -e 's/^"//' -e 's/"$//')
	result+="$AppName"
	echo "### Result - $result"
	
done

echo -e "### Result-TEST - $result"

#echo -e "<result>$result</result>"

exit 0

 

And this is the Result I get

### Result - Push Diagnostics.app
### Result - Push Diagnostics.appiMazing Profile Editor.app
### Result-TEST - 

 

How can I transfer the $result from the loop to the end of the script?
Thanks in advance!

1 ACCEPTED SOLUTION

JevermannNG
Contributor III

Hi @daniel_behan 

thanks for the help, my "problem" is solved :-)
This is the EA which I use now:

#!/bin/bash
# Extensions Atrribute: Find all appstore apps in /Applications
# lists all apps not bought through VPP (Self Service)
# Based on Scripts from Heiko Horn 2020-04-16 and Craig Lindsey for Starz 2017-2-10

checkMD=$(mdfind -onlyin /Applications/ 'kMDItemAppStoreReceiptIsVPPLicensed == "0"')
#echo "### checkMD - $checkMD"

if [ "$checkMD" = "" ]
then
	echo "<result>Not Found</result>"
	exit 0
fi

# initialise a array list
arrAppStoreApps=()
# search the metadata for apps that were installed from the app store
arrAppStoreApps=$(mdfind -onlyin /Applications/ 'kMDItemAppStoreReceiptIsVPPLicensed == "0"')
# sort the array list
sorted=$(printf '%s\n' "${arrAppStoreApps[@]} "|sort)

echo "<result>${sorted}</result>"

 

And this is the output I was looking for:

<result>/Applications/Push Diagnostics.app
/Applications/iMazing Profile Editor.app </result>

View solution in original post

4 REPLIES 4

daniel_behan
Contributor III

Here's the one I use to list App Store Apps, but I'm not parsing out which ones were assigned by VPP.

#!/bin/bash
# Extensions Atrribute: Find all appstore apps on this mac
# lists all apps from the apps store
# written by Heiko Horn 2020-04-16

# initialise a array list
arrAppStoreApps=()
# search the metadata for apps that were installed from the app store
arrAppStoreApps=$(mdfind "kMDItemAppStoreHasReceipt=1")
# sort the array list
sorted=$(printf '%s\n' "${arrAppStoreApps[@]}"|sort)

echo "<result>${sorted}</result>"

JevermannNG
Contributor III

Hi @daniel_behan 

thanks for the help, my "problem" is solved :-)
This is the EA which I use now:

#!/bin/bash
# Extensions Atrribute: Find all appstore apps in /Applications
# lists all apps not bought through VPP (Self Service)
# Based on Scripts from Heiko Horn 2020-04-16 and Craig Lindsey for Starz 2017-2-10

checkMD=$(mdfind -onlyin /Applications/ 'kMDItemAppStoreReceiptIsVPPLicensed == "0"')
#echo "### checkMD - $checkMD"

if [ "$checkMD" = "" ]
then
	echo "<result>Not Found</result>"
	exit 0
fi

# initialise a array list
arrAppStoreApps=()
# search the metadata for apps that were installed from the app store
arrAppStoreApps=$(mdfind -onlyin /Applications/ 'kMDItemAppStoreReceiptIsVPPLicensed == "0"')
# sort the array list
sorted=$(printf '%s\n' "${arrAppStoreApps[@]} "|sort)

echo "<result>${sorted}</result>"

 

And this is the output I was looking for:

<result>/Applications/Push Diagnostics.app
/Applications/iMazing Profile Editor.app </result>

daniel_behan
Contributor III

@JevermannNG you may want to double check your EA.  For me it showed an App Store app that was not assigned via VPP.  This tweak seems to show me only VPP-assigned apps.

#!/bin/bash
# Extensions Atrribute: Find all VPP Assigned appstore apps in /Applications

# initialise a array list
arrAppStoreApps=()
# search the metadata for apps that were installed from the app store
arrAppStoreApps=$(mdfind -onlyin /Applications/ 'kMDItemAppStoreReceiptIsVPPLicensed == "1"')
# sort the array list
sorted=$(printf '%s\n' "${arrAppStoreApps[@]} "|sort)

echo "<result>${sorted}</result>"

daniel_behan
Contributor III

Nevermind.  I misread your post.  That's exactly what you were looking for.