Script to delete Outlook and Teams cache

New Contributor II

I need some help and guidance with the cleanup of the Outlook and Teams caching. Sometimes it is needed to delete those. So i made a script and want to publish is througt the selfservice App. So if our servicedesk advices someone to delete the cache, it can be done by the user. However, my scripting is not that great.

I want to present a popup with 3 choices to the user. Clear Outlook cache, clear Teams cache or quit. The latter one if the user is curious :-)

This is what i have so far but it errors out. What am i doing wrong or is there a better solution to this problem?

# Clean up script!
# Task - Clear outlook address cache list!
# Task - Clear Teams caching!
#echo on if needed
#set -x

SURETY="$(osascript -e 'display dialog "Delete the cache files?" buttons {"Teams", "Outlook", "Cancel"} default button "Cancel" with icon stop')"

if [ "$SURETY" = "button returned:Outlook" ]; then
    echo "Fine, let's delete some Outlook caching."
    cd ~/Library/Group Containers/
    find . -name "*.olk15RecentAddresses" -type f|xargs rm -f

else if [ "$SURETY" = "button returned:Teams" ]; then
    echo "Fine, let's delete some Teams caching."
    rm -rf ~/Library/Caches/
    rm -rf ~/Library/Application Support/Microsoft/Teams/Application Cache/Cache
    rm -rf ~/Library/Application Support/Microsoft/Teams/blob_storage
    rm -rf ~/Library/Application Support/Microsoft/Teams/Cache
    rm -rf ~/Library/Application Support/Microsoft/Teams/databases
    rm -rf ~/Library/Application Support/Microsoft/Teams/GPUCache
    rm -rf ~/Library/Application Support/Microsoft/Teams/IndexedDB
    rm -rf ~/Library/Application Support/Microsoft/Teams/Local Storage
    rm -rf ~/Library/Application Support/Microsoft/Teams/tmp
end if

else if [ "$SURETY" = "button returned:Cancel" ]; then
    echo "Nothing to do, let's quit."
end if

# Exit
exit 0



Contributor III

You might want to check out

Thanks, Paul.

View solution in original post


Contributor III

You might want to check out

Thanks, Paul.

Contributor III

Best IT Support tool ;-)

Contributor III

+1 for @pbowden and Office Reset. Its helped a few users in our environment.

New Contributor

Really magnificent tool! Thank´s a lot!