-
-
Save pythoninthegrass/9e4d3ef0f2036746467add17c76b4c15 to your computer and use it in GitHub Desktop.
Uninstall Microsoft Office from macOS completely
This file contains 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
#!/usr/bin/env bash | |
# SOURCES: | |
# https://gist.github.com/pirafrank/18d62c062e2806c1d183 | |
# SEE THIS EXCELLENT SITE IF GIST FAILS: | |
# https://office-reset.com | |
# activate verbose standard output (stdout) | |
set -v | |
# activate debugging (execution shown) | |
set -x | |
# strict error checking | |
# set -e | |
# Logs | |
log_time=$(date +%Y%m%d_%H%M%S) | |
# log_file="/tmp/$(basename "$0" | cut -d. -f1)_$log_time.log" # LOCAL only | |
log_file="/tmp/_$log_time.log" | |
exec &> >(tee -a "$log_file") # redirect standard error (stderr) and stdout to log | |
# exec 1>> >(tee -a "$log_file") # redirect stdout to log | |
# $USER | |
# Param $3 is logged in user in JSS | |
if [[ ! -z "$3" ]]; then | |
logged_in_user=$3 | |
else | |
logged_in_user=$(logname) # posix alternative to /dev/console | |
fi | |
# $UID | |
# logged_in_uid=$(id -u "${logged_in_user}") | |
# $HOME | |
# logged_in_home=$(eval echo "~${logged_in_user}") | |
# Working directory | |
if [[ -z "$3" ]]; then | |
script_dir=$(cd "$(dirname "$0")" && pwd) | |
else | |
script_dir=$(mktemp -d) | |
cd "$script_dir" | |
fi | |
# Set $IFS to eliminate whitespace in pathnames | |
IFS="$(printf '\n\t')" | |
# Remove MS Apps sans RDP | |
apps_array=($(find /Applications -maxdepth 1 -name "Microsoft*" ! -name "*Remote Desktop*")) | |
# printf '%s ' "${app_array[@]}" | |
echo "Removing Office 2016 apps..." | |
for a in "${apps_array[@]}"; do | |
echo "Removed $a." | |
[[ -d "$a" ]] && rm -rf "$a" | |
done | |
# ~/Library PLISTs | |
declare -a plist_array=( | |
com.microsoft.errorreporting | |
com.microsoft.Excel | |
com.microsoft.netlib.shipassertprocess | |
com.microsoft.Office365ServiceV2 | |
com.microsoft.Outlook | |
com.microsoft.Powerpoint | |
com.microsoft.RMS-XPCService | |
com.microsoft.Word | |
com.microsoft.onenote.mac | |
) | |
# printf '%s ' "${userLibrArray[@]}" | |
echo "Cleaning ~/Library..." | |
cd "/Users/${logged_in_user}/Library/Containers" || exit | |
for u in "${plist_array[@]}"; do | |
# echo "Removed $u." | |
[[ -f "$u" ]] && rm -f "$u" | |
done | |
cd "/Users/${logged_in_user}/Library//Group Containers" || exit | |
con_array=($(find "/Users/${logged_in_user}/Library/Group Containers" -maxdepth 1 -name "UBF8T346G9*")) | |
for c in "${con_array[@]}"; do | |
# echo "Removed $c." | |
[[ -f "$c" ]] && rm -f "$c" | |
done | |
# further cleaning | |
echo "Cleaning system folders..." | |
[[ -e "/Library/Application Support/Microsoft/MAU2.0" ]] && rm -rf "/Library/Application Support/Microsoft/MAU2.0" | |
[[ -e "/Library/Fonts/Microsoft" ]] && rm -rf "/Library/Fonts/Microsoft" | |
# /Library PLISTs | |
declare -a plist_array=( | |
com.microsoft.office.licensing.helper.plist | |
com.microsoft.office.licensingV2.helper.plist | |
com.microsoft.Excel.plist | |
com.microsoft.office.plist | |
com.microsoft.office.setupassistant.plist | |
com.microsoft.outlook.databasedaemon.plist | |
com.microsoft.outlook.office_reminders.plist | |
com.microsoft.Outlook.plist | |
com.microsoft.PowerPoint.plist | |
com.microsoft.Word.plist | |
com.microsoft.office.licensingV2.plist | |
com.microsoft.autoupdate2.plist | |
com.microsoft | |
com.microsoft.office.licensing.helper | |
com.microsoft.office.licensingV2.helper | |
) | |
# printf '%s ' "${plist_array[@]}" | |
for s in "${plist_array[@]}"; do | |
# echo "Removed $s." | |
[[ -f "$s" ]] && rm -f "$s" | |
done | |
# MSO 2016 legacy receipts; not present in newer 365 installs | |
find "/Library/Receipts" -name "Office2016_*" -exec -rm -r -rf {} \; | |
# STATIC | |
# /Library PLISTs | |
# declare -a pkg_array=( | |
# com.microsoft.package.DFonts | |
# com.microsoft.package.Fonts | |
# com.microsoft.package.Frameworks | |
# com.microsoft.package.Microsoft_AutoUpdate.app | |
# com.microsoft.package.Microsoft_Excel.app | |
# com.microsoft.package.Microsoft_OneNote.app | |
# com.microsoft.package.Microsoft_Outlook.app | |
# com.microsoft.package.Microsoft_PowerPoint.app | |
# com.microsoft.package.Microsoft_Word.app | |
# com.microsoft.package.Proofing_Tools | |
# com.microsoft.package.licensing | |
# ) | |
# DYNAMIC | |
pkg_array=($(pkgutil --pkgs-plist | awk -F '[<>]' '/com.microsoft.package/ {print $3}')) | |
# printf '%s\n' "${$pkg_array[@]}" | |
echo "Making your Mac forget about Office 2016..." | |
for p in "${pkg_array[@]}"; do | |
# echo "Removed $p." | |
[[ ! -z "$p" ]] && pkgutil --forget "$p" | |
done | |
echo "Fini!" | |
# deactivate verbose and debugging stdout | |
set +v | |
set +x | |
unset IFS | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey there.
Apologies for the delay, don't monitor this gist, but in the stderr output, it tells you what happened -- on line 8, a stray single quote got added to the script reading
exec &> >(tee -a "$uninstallLog")'
instead ofexec &> >(tee -a "$uninstallLog")
.Cheers