Commits

Hasani Hunter committed d773efb

Initial file creation.

Comments (0)

Files changed (1)

office_remover.py

+
+# This python script is created from information from microsoft's Knowledge Base article "How to completely remove Office for Mac 2011"
+# found http://support.microsoft.com/kb/2398768
+import sys
+import shutil
+import glob
+import os
+
+office_folder = "/Applications/Microsoft Office 2011"
+
+# Make sure that the number of arguments are 1, <OFFICE folder>
+if len(sys.argv) == 2:
+    # The user is overwriting the default Microsoft Office folder
+    office_folder = sys.argv[1]
+
+# Move the application folder to the trash
+move_path_to_trash(office_folder)
+
+# Move all preference files that start with com.microsoft to the trash
+
+# user library folder
+user_preference_folder = os.path.join(os.path.expanduser("~"),"Library","Preferences")
+# Grab a list of micosoft preference files
+preference_file_list = get_glob_file_for_path(user_preference_folder,"com.microsoft.*")
+# Loop through each preference
+for ( preference_file in preference_file_list):
+	# move each preference file to the user's trash
+	move_path_to_trash(preference_file)
+
+# We now need to move the /Users/<user>/Library/Preferences/Microsoft/Office 2011 folder into the user's trash
+preference_office_folder = os.path.join(user_preference_folder,"Microsoft","Office 2011")
+move_path_to_trash(preference_office_folder)
+
+# Remove the helper plist
+helper_plist = os.path.join("/Library","LaunchDaemons","com.microsoft.office.licensing.helper.plist")
+move_path_to_trash(helper_plist)
+
+# We need to remove the helper binary itself
+helper_binary = os.path.join("/Library","PrivilegedHelperTools","com.microsoft.office.licensing.helper")
+move_path_to_trash(helper_binary)
+
+# move the license plist to the trash
+license_plist = os.path.join("/Library","Preferences","com.microsoft.office.licensing.plist")
+move_path_to_trash(license_plist)
+
+# Move the support folder
+support_folder = os.path.join("/Library","Application Support","Microsoft")
+move_path_to_trash(support_folder)
+
+# warn the user
+print "If Silverlight is currently installed, you will have to reinstall"
+print "Silverlight can be reinstalled from: http://www.microsoft.com/getsilverlight/get-started/install/default.aspx"
+
+# Remove receipts
+receipt_folder = os.path.join("/Library","Receipts")
+
+all_office_2011_files_list = get_glob_list_for_path(receipt_folder,"Office2011_*")
+
+for ( office_file_path in all_office_2011_files_list ):
+	# remove each receipt file
+	move_path_to_trash(office_file_path)
+
+# Remove other receipts in /private/var/db/receipts
+private_receipt_folder = os.path.join("/private","var","db","receipts")
+
+if os.path.exists(private_receipt_folder):
+	# move all files that begin with "com.microsoft.office" and move to the trash
+	# Look for all files that begin with "com.microsoft.office"
+	private_receipt_file_list = get_glob_list_for_path(private_receipt_folder,"com.microsoft.office*")
+
+	for (private_receipt_file in private_receipt_file_list):
+		# Move to trash
+		move_path_to_trash(private_receipt_file)
+
+# Move custom templates to the trash
+custom_template_path = os.path.join(os.path.expanduser("~"),"Library","Application Support","Microsoft","Office")
+move_path_to_trash(custom_template_path)
+
+# Move any custom fonts to the trash
+custom_font_folder = os.path.join("/Library","Fonts","Microsoft")
+move_path_to_trash_(custom_font_folder)
+
+print "Finished removing Office 2011, Please remove any Office 2011 applications from your Dock and restart your Mac"
+
+# This function just moves the path to the user's Trash folder
+def move_path_to_trash(path):
+	# ensure that the path exists.. if not then silently fail
+	if os.path.exists(path):
+		# grab the home directory of the user
+		user_home = os.path.expanduser("~")
+		# The trash folder resides in ~/user/.Trash
+		trash_folder = os.path.join(user_home,".Trash")
+		# Move the path to the user .Trash folder
+		shutil.move(path, trash_folder)
+
+def get_glob_list_for_path(path,regex):
+	glob_text = "{0}/{1}".format(path,regex)
+	return glob.glob(glob_text)
+