Created
August 27, 2019 03:19
-
-
Save bwmorales/b579e49ef8b0d6d9eeb0841d9ed432cb to your computer and use it in GitHub Desktop.
macOS: check whether office applications have been opened in the last 30 days.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
currentDate=$(date "+%s") | |
applicationList=( | |
"/Applications/Microsoft Word.app" | |
"/Applications/Microsoft Excel.app" | |
"/Applications/Microsoft PowerPoint.app" | |
"/Applications/Microsoft Outlook.app" | |
"/Applications/Microsoft OneNote.app" | |
"/Applications/Microsoft Teams.app" | |
"/Applications/Yammer.app" | |
"/Applications/Skype for Business.app" | |
) | |
| |
oIFS=$IFS | |
IFS=$'\n' | |
underutilizedApps="0" | |
utilizedApps="0" | |
installedApps="0" | |
printf "Total Apps: ${#applicationList[@]}\n" | |
for application in ${applicationList[@]}; do | |
if [[ -e "$application" ]]; then | |
installedApps=$(($installedApps + 1)) | |
lastUsedDate="$(mdls "$application" -name kMDItemLastUsedDate | awk '{ print $3 }')" | |
if [[ "$lastUsedDate" != "(null)" ]]; then | |
secondsSinceUse=$(($currentDate - $(date -jf "%Y-%m-%d" "$lastUsedDate" "+%s"))) | |
printf "%s was last used %s days ago.\n" "$application" "$(expr $secondsSinceUse / 86400)" | |
if [[ $secondsSinceUse -gt 2592000 ]]; then | |
underutilizedApps=$(($underutilizedApps + 1)) | |
else | |
utilizedApps=$(($utilizedApps + 1)) | |
fi | |
else | |
printf "%s has never been used.\n" "$application" | |
underutilizedApps=$(($underutilizedApps + 1)) | |
fi | |
else | |
: | |
printf "%s is not present.\n" "$application" | |
fi | |
done | |
IFS=$oIFS | |
printf "Total Unused in Last 30 Days: %s\n" "$underutilizedApps" | |
printf "Utilization: %s/%s\n" "$utilizedApps" "$installedApps" | |
if [[ "$installedApps" -eq "0" ]]; then | |
exit 0 | |
elif [[ "$underutilizedApps" -eq "$installedApps" ]]; then | |
exit 1 | |
else | |
exit 0 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment