clean up/logout function to remove preferences

walt
Contributor III

I have a basic script, that I'm looking to turn in a clickable button for our technicians that will remove preferences and items stored on a loaner device without reimaging each time.

A few items I'm not able to completely remove or clean up are:
• closing all windows at logout
• turning off open all windows from last session
• removing the ~/Library/Safari (I can manually do this in terminal, but not from the script) example: rm -Rf /Users/$USER/Library/Safari/* (does not work in script)

maybe instead, figure out a way to enforce/enable Private Browsing Safari each time, would resolve that.

Here is the gritty script, all the items in here work, just can't figure out the above items

#!/bin/sh

# Remove Keychain items
rm -Rf /Users/$USER/Library/Keychains/*

# Remove Safari items
rm -Rf /Users/$USER/Library/SafariSafeBrowsing/*
rm -Rf /Users/$USER/Library/Saved Application State/com.apple.Safari.*
rm -Rf /Users/$USER/Library/Preferences/com.apple.Safari.*
rm -Rf /Users/$USER/Library/Containers/com.apple.Safari/*
rm -Rf /Users/$USER/Library/Containers/com.apple.Safari*

# Remove Chrome items
rm -Rf /Users/$USER/Library/Safari/*
rm -Rf /Users/$USER/Library/Application Support/Google/*
rm -Rf /Users/$USER/Library/Preferences/com.google.Chome.*
rm -Rf /Users/$USER/Library/Saved Application State/com.google.*

# Removes Desktop items
rm -Rf /Users/$USER/Desktop/*

# Removes Documents items
rm -Rf /Users/$USER/Documents/*

# Removes Downloads items
rm -Rf /Users/$USER/Downloads/*

# Removes Outlook profiles items
rm -Rf /Users/$USER/Library/Group Containers/UBF*

# Removes Microsoft/Outlook items
rm -Rf /Users/$USER/Library/Containers/com.microsoft.*

# Removes Skype and Microsoft items
rm -Rf /Users/$USER/Library/Logs/LwaTracing
rm -Rf /Users/$USER/Saved Application State/com.microsoft.*
rm -Rf /Users/$USER/Library/Preferences/com.microsoft.*
rm -Rf /Library/Internet Plug-Ins/MeetingJoinPlugin.plugin

# Removes Cache items
rm -Rf /Users/$USER/Library/Caches/*

# Removes Preferences items
rm -Rf /Users/$USER/Library/Preferences/*


# Empty Trash
rm -R ~/.Trash/*

# Log-out current user
killall loginwindow

exit 0
0 REPLIES 0