Delete Unused Application?

musat
Contributor III

Hello,
I am trying to figure out a way to delete an application if it has been unused. We have 100 or so licenses of iWork, that were purchased prior to bringing back MS Office. I would like to delete those instances of the iWork applications on those Macs that they haven't been run on. I can go to the "Computers" tab in the JSS and search on "Application Usage", and in this way get a list of the 20 or so computers that have some usage history of the individual apps. However, this search screen doesn't have the option to create a Group from this list. And it doesn't look like Application Usage is an option when creating a Smart Group. Do I really have to create these groups manually, so that I can exclude them from Policy that will delete the applications?

Tim

2 REPLIES 2

mm2270
Legendary Contributor III

Which JSS version? IN the older 8 series of Casper there was a way to do this directly from the Application Usage section. IN addition to the Macs that had some usage data, it had a tab to show all Macs that had no usage data for the specified application)(s)
I think this is missing now in Casper Suite 9, which from your description sounds like what you're using. If so, you might want to get with JAMF on their recommendation here. There may be a way in the GUI to do it that I'm just not aware of, or, they may be able to help you do this directly from the MySQL command line.

Another option would be yet another Extension Attribute to gather some usage data. This seems like a silly approach given the JSS already captures this, but since it won't let you natively build a Smart Group from the information, you might have to take matters in your own hands.

Most folks don't know that Spotlight captures application launches in a couple of arrays that get stored in the metadata of the application.
While not perfect, you could simply pull the Item Use Count for the applications with something like this (not certain about the path, so adjust if needed)-

mdls /Applications/Utilities/iWork/Keynote.app -name kMDItemUseCount | awk '$0 !~ "(null)" { print $NF }'

That pulls an integer value, like 20 or whatever if a count exists. If not, it pulls back a blank value, since I'm telling awk to only print the last column if the result doesn't contain "(null)" somewhere in it. For any apps that have never been launched mdls returns a result like:

kMDItemUseCount = (null)

You could also just tell it to print the last column regardless and some will be (null) and others will have a value. In your Smart Group, look for any Macs that have a Use Count that equals "(null)" to gather the ones that have never run the application. Then have the policy uninstall those apps.

One thing to keep in mind is that mdls reports usage from the beginning of when it indexed the application, so that could span years. If you wanted something like only pulling Macs that haven't run it within the last 60 days for example, that could be done, but would be a little more work in the script.

gabester
Contributor III

I just had to remove an application that was accidentally deployed to multiple Macs. I wrote this script leveraging the logic of the line above but also adding a pipe through grep -v "not find" since mdld will return that if the path is not found; I'm using parameter $4 for the app name and $5 for the path it resides on. Then I scoped a policy to run this script to a smart group of Macs that had the app in question deployed. Oh, and I exit 1 so that if the app is found to have been launched I can get a sense of how many actually were used by counting the failures of the policy.

#!/bin/sh
# validate or default parameters
if [ -z $4 ]; then 
    APPNAME="Firefox.app"
else 
    APPNAME=$4
fi

if [ -z $5 ]; then 
    APPPATH="/Applications/"
else 
    APPPATH=$5
fi

COUNT=$(/usr/bin/mdls $APPPATH$APPNAME -name kMDItemUseCount | grep -v "not find" | awk '$0 !~ "(null)" { print $NF }')
if [ ! $COUNT ]; then
    echo "Removing unused $APPPATH$APPNAME"
    /bin/rm -rf $APPPATH$APPNAME
else
    echo "Usage for $APPPATH$APPNAME = $COUNT" 
    exit 1
fi