Clear Chrome Cache on Login

irod87
New Contributor

Does anyone have a script that will clear Google Chrome cache on login and or logout? I've having an issue where chrome is locking up waiting for the cache. Once cleared the browser works fine.

4 REPLIES 4

irod87
New Contributor

I came up with these lines that seem to work to remove the Chrome Folder and the Profiles.ini from Firefox. I need this to run when a network user logs in and it needs to clear the files from their network account since they do not create a local account.

!/bin/bash

rm -R ~/Library/'Application Support'/Google/Chrome

rm -R ~/Library/'Application Support'/Firefox/profiles.ini

I saved this as a .sh an put it in Casper Admin. These set a policy to run at login. It would run and say successful but the logs would say file not found.

mpermann
Valued Contributor II

@irod87 the ~ character doesn't expand to the user that you are trying to delete the files from. When you run a command from Casper it typically is running as root. So that would delete the files located in root's home directory. You need to get the logged in user. There are lots of examples in other threads on how to do this. I've used the python snippet below that I found in a JAMF Nation thread to get the logged in user.

loggedInUser=`python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
");'`

Then I believe your command would look like

rm -R /Users/$loggedInUser/Library/Application Support/Google/Chrome

Be sure to test this before putting this into production as I am NOT a scripting guru.

Look
Valued Contributor III

All those commands look to be clearing the profile, basically reseting Chrome back to defaults which unless your using Chrome Master Preferences or Config Profile will be as it came from Google.
The cache files look to be in.

~/Library/Caches/Google/Chrome

@irod87 when you say clearing the cache fixes it how are you going about this manually?

irod87
New Contributor

We find that deleting the Google folder seems to fix things. Which does result it the browser going back to factory settings. As far as just clearing the cache we do that manually through preferences. Perhaps the profiles are getting corrupt and deleting the Google folder fixes the problem.