bash,  Mac OS X

One Liner to Loop Through a Directory for Last Used Date of Apps on a Mac

Here we load in a list of Apps in the /Applications directory and then echo them along with the kMDItemLastUsedDate from Spotlight via mdls:

ls /Applications | while read APP;do echo "$APP" ; echo `/usr/bin/mdls /Applications/"$APP" |  /usr/bin/grep -w kMDItemLastUsedDate`; done

The output per item would then look something like this:

Apple Configurator.app
kMDItemLastUsedDate = 2022-09-27 18:25:21 +0000

awk can get the $3 if that’s all that’s needed or other filtering tools can limit the output. Or get more output, like a bundle ID (kMDItemCFBundleIdentifier) or an Apple Store ID (kMDItemAppStoreAdamID) for parsing through other tools. Further no need to echo the string of the name of the app according to how the data is being used, so that first echo could easily be removed.

Note: There are items in /Applications that aren’t called directly (e.g. filters for other apps). Not all apps have been opened either. Therefore, not all entries would have a last used date.