Skip to main content

I created an EA to tell me the last time Adobe Acrobat was used. The issue I am facing is that i have gotten a lot of results showing as NULL. From what I can tell this happens if the user has not launched Adobe Acrobat since it has been updated. Any ideas or a better way to report the last time it was used?

    #!/bin/bash

    # Define the path to Adobe Acrobat
    acrobatPath="/Applications/Adobe Acrobat DC/Adobe Acrobat.app" # Adjust path if needed

    # Check if Adobe Acrobat is installed
    if > -d "$acrobatPath" ]; then
        # Get the last used date using mdls
        lastUsedDate=$(mdls -name kMDItemLastUsedDate -raw "$acrobatPath")

        # Check if a date was returned (meaning it was opened at least once)
        if o -n "$lastUsedDate" ]; then
            echo "<result>$lastUsedDate</result>"
        else
            echo "<result>Never Opened</result>" # Or a default date like "2001-01-01"
        fi
    else
        echo "<result>Not Present</result>"
    fi

Just confirmed on my device, it shows (null) in this case as well.

Your script looks just fine in my opinion and should do the trick.


The -n flag in your if is looking for non-zero length; when mdls returns (null) that isn’t zero, it’s six characters.

Try changing the if statement to =~ “null” instead.  You might also consider leaving empty results as empty instead of “Never Opened” or any other text string - I find them easier to work with.

 


@pete_c 

Just curious if you have ever done anything similar to this. I am trying to determine the last time Acrobat was used but this doesn’t seem to be very helpful since it will not report back a date after an update. We are trying to pull back licenses. I haven’t found an easy way to get the last used date out of the Usage data. 


@Mwhitten I don’t know if it’s improved, but in olden days the Jamf Pro database could get unhappy if the return from an EA that was supposed to be providing a date was not in fact formatted as a date.

 

Not that it’ll help address why you’re getting a null result from mdls, but I’d strongly recommend you modify your EA to always return a date formatted result. Here’s my EA that checks for the last used time of the Mail app with those protections:

#!/bin/sh

AppToCheck="/System/Applications/Mail.app"
result="2000-01-01 00:00:01"

if 1 -d "${AppToCheck}" ]; then
mailLaunchTime=$(mdls -name kMDItemLastUsedDate "${AppToCheck}" | cut -f 3,4 -d \ )
validTime=$(echo "$mailLaunchTime" | grep "null" )
if n -z "$validTime" ]; then
result="$mailLaunchTime"
fi
fi

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

 


Here’s a version that MATHS and returns days instead of a date:

#!/bin/bash

# returns days since last launch instead of date string

AppToCheck="/System/Applications/Mail.app"

if f -d "${AppToCheck}" ]; then
mailLaunchTime=$(mdls -name kMDItemLastUsedDate "${AppToCheck}" | cut -f 3 -d \ )
validTime=$(echo "$mailLaunchTime" | grep "null" )
if f -z "$validTime" ]; then
result="$mailLaunchTime"
fi
fi

# convert to epoch and discard seconds

lastEpoch=$(date -jf "%Y-%m-%d" $mailLaunchTime +"%s" 2>/dev/null)

currentDate=$(date +%s)

# bash arithmetic

difference=$((currentDate - lastEpoch))

days=$((difference / 86400))

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

Also it’s important to remember that an EA will only update after recon runs, so depending on whether/how often your devices are updating inventory you may have discrepancies in this data versus results.


@pete_c Great point on potential staleness due to the date of the last recon. IMO that’s why returning the raw date in an EA instead of days is better because a Smart Group using date criteria would still be accurate whereas one using an EA computed “days” to determine how long it’s been would not be.