Skip to content

Instantly share code, notes, and snippets.

@bwmorales
Created August 27, 2019 03:20
Show Gist options
  • Save bwmorales/1128138bbc048a084af70f2db882751d to your computer and use it in GitHub Desktop.
Save bwmorales/1128138bbc048a084af70f2db882751d to your computer and use it in GitHub Desktop.
macOS: Addigy custom fact for checking if people are using Office 365
#!/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"
)
oIFS=$IFS
IFS=$'\n'
underutilizedApps="0"
utilizedApps="0"
installedApps="0"
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")))
if [[ $secondsSinceUse -gt 2592000 ]]; then
underutilizedApps=$(($underutilizedApps + 1))
else
utilizedApps=$(($utilizedApps + 1))
fi
else
underutilizedApps=$(($underutilizedApps + 1))
fi
fi
done
IFS=$oIFS
if [[ "$installedApps" -eq "0" ]]; then
printf "TRUE\n"
exit 0
fi
if [[ "$underutilizedApps" -eq "$installedApps" ]]; then
printf "FALSE\n"
else
printf "TRUE\n"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment