Mac move logs and caches to RAM

how to use a RAM disk to store caches and logs so you can avoid unnecessary disk writes. This is for Catalina. There’s no point in trying to control later Macs as they are not your own any more.

This shell script that removes the cache folders, creates them on a RAM disk and creates symlinks for them so the applications don’t know it’s even happening. The first file is the shell script that does the actual work:

#!/bin/bash
while [ ! -d /Volumes ]
do
 echo "waiting..."
 sleep 0.5
done
if [ ! -d /Volumes/RamDisk ]; then
 echo "creating ramdisk..."
 sleep 0.5
 diskutil partitionDisk $(hdiutil attach -nomount ram://$((2048*16000))) 1 GPTFormat APFS 'RamDisk' '100%'
 mkdir -p /Volumes/RamDisk/Logs/
 sudo rm -rf /private/var/log
 ln -s /Volumes/RamDisk/Logs /private/var/log
 sudo rm -rf /Users/guy/Library/Logs
 ln -s /Volumes/RamDisk/Logs /Users/guy/Library/Logs
 sudo rm -rf /Library/Logs
 sudo ln -s /Volumes/RamDisk/Logs /Library/Logs
 rm -rf /Users/guy/Library/Application\ Support/Adobe/ExtensibilityLibrary/Log
 ln -s /Volumes/RamDisk/Logs /Users/guy/Library/Application\ Support/Adobe/ExtensibilityLibrary/Log
 rm -rf /Users/guy/Library/Application\ Support/Adobe/Extension\ Manager\ CC/Log
 ln -s /Volumes/RamDisk/Logs /Users/guy/Library/Application\ Support/Adobe/Extension\ Manager\ CC/Log
 mkdir -p /Volumes/RamDisk/Downloads
 sudo rm -rf /Users/guy/Downloads
 sudo ln -s /Volumes/RamDisk/Downloads /Users/guy
 sudo chown guy:staff /Users/guy/Downloads
 declare -a arr=(
 "Adobe Camera Raw 2"
 "Adobe_CCXProcess.node"
 "askpermissiond"
 "BraveSoftware"
 "com.adobe.acc.AdobeDesktopService"
 "com.adobe.acc.ads.helper"
 "com.adobe.bridge10"
 "com.adobe.headlights.LogTransport2App"
 "com.apple.akd"
 "com.apple.AMPLibraryAgent"
 "com.apple.AppleMediaServices"
 "com.apple.appstore"
 "com.apple.appstoreagent"
 "com.apple.cache_delete"
 "com.apple.commerce"
 "com.apple.helpd"
 "com.apple.iBooksX"
 "com.apple.icloud.fmfd"
 "com.apple.iCloudHelper"
 "com.apple.imfoundation.IMRemoteURLConnectionAgent"
 "com.apple.InstallAssistant.macOS1016"
 "com.apple.installer"
 "com.apple.installer.osinstallersetupd"
 "com.apple.nbagent"
 "com.apple.nsurlsessiond"
 "com.apple.parsecd"
 "com.apple.passd"
 "com.apple.proactive.eventtracker"
 "com.apple.remindd"
 "com.apple.Spotlight"
 "com.apple.touristd"
 "com.apple.VideoConference"
 "com.apple.XprotectFramework.AnalysisService"
 "com.brave.Browser"
 "com.crashlytics.data"
 "com.dustinrue.ControlPlane"
 "com.flixtools.flixtools"
 "com.Google.GoogleDrive"
 "com.google.GoogleEarthPro"
 "com.google.Keystone"
 "com.google.SoftwareUpdate"
 "com.intel.PowerGadget"
 "com.MattRajca.RetinaCapture"
 "com.microsoft.autoupdate.fba"
 "com.microsoft.autoupdate2"
 "com.microsoft.edgemac"
 "com.microsoft.teams"
 "com.operasoftware.Installer.Opera"
 "com.operasoftware.Opera"
 "com.panic.Transmit"
 "com.plausiblelabs.crashreporter.data"
 "com.runningwithcrayons.Alfred"
 "com.spotify.client"
 "com.teamviewer.TeamViewer"
 "CSXS"
 "FamilyCircle"
 "familycircled"
 "GeoServices"
 "Google"
 "Google Earth"
 "knowledge-agent"
 "ksfetch"
 "Maps"
 "Microsoft"
 "Microsoft Edge"
 "net.freemacsoft.AppCleaner"
 "net.pornel.ImageOptim"
 "node"
 "PassKit"
 "TeamViewer"
 "Transmit"
 )
 for i in "${arr[@]}"
 do
 mkdir -p "/Volumes/RamDisk/Caches/$i"
 if [[ -L "/Users/guy/Library/Caches/$i" && -d "/Users/guy/Library/Caches/$i" ]]
 then
 echo "$i is already a symlink"
 else
 rm -rf "/Users/guy/Library/Caches/$i"
 ln -s "/Volumes/RamDisk/Caches/$i" /Users/guy/Library/Caches
 echo "$i CREATED"
 fi
 done
fi

That file is executed on system startup by a LaunchAgent, the file is stored as /Library/LaunchAgents/com.user.ramdisk.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
 <key>Label</key>
 <string>com.user.ramdisk</string>
 <key>ProgramArguments</key>
 <array>
 <string>/Users/guy/OneDrive/MyApps/createramdiskatboot.command</string>
 </array>
 <key>RunAtLoad</key>
 <true/>
 <key>StartInterval</key>
 <integer>300</integer>
</dict>
</plist>

Then enable the launch agent:

launchctl enable /Library/LaunchAgents/com.user.ramdisk.plist

 reboot your Mac and watch the RamDisk to see if everything’s working: