Finder.app: Clear the Cache Folders of user domain (selectively)

The following simple script will help you quickly clear the cache selectively when some application or service significantly slows down your computer.

As you can see, at the top of the script, the user sets the list of applications and servers that will be allowed to be cleared.


set cashesAllowedToDelete to {"CloudKit", "FamilyCircle", "GameKit", "GeoServices", "Google", "Maps", "PassKit", "Script Debugger", "SentryCrash", "askpermissiond", "com.apple.AMPLibraryAgent", "com.apple.AppleMediaServices", "com.apple.Spotlight", "com.apple.akd", "com.apple.ap.adprivacyd", "com.apple.appstore", "com.apple.appstoreagent", "com.apple.bird", "com.apple.cache_delete", "com.apple.cloudd", "com.apple.gamed", "com.apple.helpd", "com.apple.iCloudHelper", "com.apple.icloud.fmfd", "com.apple.imfoundation.IMRemoteURLConnectionAgent", "com.apple.nbagent", "com.apple.nsurlsessiond", "com.apple.parsecd", "com.apple.passd", "com.apple.proactive.eventtracker", "com.apple.remindd", "com.apple.touristd", "com.google.Keystone", "com.google.SoftwareUpdate", "com.latenightsw.ScriptDebugger8", "familycircled", "io.sentry", "knowledge-agent", "org.videolan.vlc"}

set LibraryAlias to path to library folder from user domain

tell application "Finder"
	set CashesFolder to folder "Caches" of LibraryAlias
	set folderNames to name of folders of CashesFolder
end tell

set cashesToDelete to (choose from list folderNames with multiple selections allowed)
if cashesToDelete is false then return

repeat with i from 1 to (count cashesToDelete)
	set casheToDelete to item i of cashesToDelete
	if casheToDelete is in cashesAllowedToDelete then
		tell application "Finder" to delete folder casheToDelete of CashesFolder
	end if
end repeat

-- tell application "Finder" to empty trash -- optional