Skip to main content

Recently, our Asset Management department expressed a desire to not only report whether or not a workstation had software installed, but also when it was last used. This information can be valuable as it would allow us to repurpose existing unused licenses rather than needlessly purchasing additional seats.



As a result, I was able to create an Extension Attribute for each application we wanted to report on by using the following code example. The Extension Attribute should be created to return a Date (Data Type) and will function in the following way:




  • IF the application is not installed, return "Not Present".

  • IF the application is installed, return the date and time it was last opened.

  • IF the application is installed, but NEVER opened, return "2001-01-01".



By using the Date (Data Type), this allows us to leverage Advanced Computer Searches to look for infrequently used software. For example, we could create an Advanced Computer Search to look for all instances of iMovie that have not been launched in more than 90 days and who's Last Inventory Update was less than 5 days ago.



So far, this has given us great insight into what our users are actually using on their workstations and helping us save a little time and money as well when it comes to license procurement or testing resources.



And because of that, I wanted to share it with the community. Enjoy!



#!/bin/bash

APPLICATION_PATH=/Applications/Self Service.app

if [ ! -e "$APPLICATION_PATH" ]; then
result="Not Present"
fi

if [ -e "$APPLICATION_PATH" ]; then
result=`mdls "$APPLICATION_PATH" | grep kMDItemLastUsedDate | awk '{ $1 = $1 } { print }' | cut -c 23-41`
fi

if [ "$result" == "" ]; then
result="2001-01-01 01:01:01"
fi

echo "<result>$result</result>"

@brock.walters when the EA encounters an application that hasn't been lunched it's returning (null) for me on 10.11.4. Are you getting a different result? Should the if statement be



if [ "$usedate" == "(null)" ]


instead of what is listed above?


what I believe is happening there is 1 of 2 things: either the application has never been opened or the Spotlight database (that's what's being examined by mdls command) may have been deleted or not updated. Your mileage may vary. 🙂



As per usual the ever-expert @mm2270 has a previous post on this very topic:



https://jamfnation.jamfsoftware.com/featureRequest.html?id=3361



Hope that helps!


Reply