MacOS – Login Script for deleting contents of /private/var/folders

accountsfoldersmacosscriptserver.app

We have fleets of laptops that have limited space once our software is installed on it. What ever the issue that is causing the creation of theses files and –err not flushing them, we are ignoring for the moment. But I would like to automatically delete the contents /private/var/folders/. We have maybe 5-10 students log in to a laptop a day. Not sure if that will be an overkill. Any help would be appreciated.

Best Answer

It's a simple way. You can use the getconf DARWIN_USER_CACHE_DIR command to get the per-user temporary files and caches directory. and remove it. edit the '/etc/profile' file, add the following codes in it(not test yet):

userTempDir=`/usr/bin/getconf DARWIN_USER_CACHE_DIR`
rm -fr $userTempDir*