Category filter
Script to view the last opened time of apps/files on macOS
This document helps administrators fetch the last opened time of apps or files from macOS devices.
Administrators have to identify when apps or files were last accessed on the device for various reasons. Managing resource-intensive modern apps is crucial for optimizing system performance. A rise in the number of apps on the device can have significant impacts like system slowdown or increased boot times. Also, monitoring the app access behavior on the device makes it easier to draw usage patterns, especially during work hours. Based on the conclusions outlined, admins may choose to uninstall unnecessary apps, freeing up space and improving efficiency. On the other hand, keeping track of the last opened time of files can contribute to basic device/user logging. Admins can execute the scripts given below to find out when an app was last opened using Hexnode UEM’s Execute Custom Script action for Macs.
Scripting language – Bash
File extension – .sh
Fetch the timestamp when the app/file was last opened
You can deploy the following script to fetch the timestamp of an app or file.
1 2 3 4 5 6 |
#!/bin/bash datetime=$(mdls "$1" -name kMDItemLastUsedDate | awk '{print $3,$4}') echo "'$1' was last opened on (UTC):" echo $datetime echo "'$1' was last opened on (Local Time):" echo $(date -jf "%Y-%m-%d %H:%M:%S %z" "$datetime +0000" +"%Y-%m-%d %H:%M:%S") |
As an argument in the Arguments field while deploying the script, provide the file path for the app or file whose last opened timestamp you want to fetch.
The output obtained provides the last opened timestamp, both according to UTC and the device’s local time.