2 Steps to a Mac Ramdisk to Speed Up Applications
No IT in context today, just something helpful that won’t fit in 140 characters. We have a non-SSD MacBook Pro at home in the kitchen that gets a lot of use by the entire family. Lately, Internet browsing has been a little slow and not because of Internet speeds. I figured I would place the browser cache on a ramdisk. Once I figured out how to do that, I figured I would place all OS caches on a ramdisk. Here is what I did:
1) Write a script that creates a 1 GB ramdisk and links the OS and user cache directories to the ramdisk
- Use your favorite text editor (I used vi) to create a shell script named create_ramdisk.sh. Here are the lines to paste into your shell script:
#Create a 1 GB ramdisk (Can also use RAMDiskCreator.app from the App Store)
diskutil erasevolume HFS+ ‘RAM_Disk’ `hdiutil attach -nomount ram://2097152`
# Create new cache directories on your ramdisk
mkdir /Volumes/RAM_Disk/OS_Caches;
mkdir /Volumes/RAM_Disk/User_Caches;
# Remove the old cache directories on your hard disk. NB:Change “dennis” to your username. Was using ~/Library until I added the sudo.
sudo rm -Rf /Users/dennis/Library/Caches;
sudo rm -Rf /Library/Caches;
# Create pointers (links) to from the MacOS hard disk cache locations to the ramdisk cache locations.
sudo ln -s /Volumes/RAM_Disk/OS_Caches /Library/Caches;
ln -s /Volumes/RAM_Disk/User_Caches ~/Library/Caches;
2) Automate the script on logon
I used AppleScript rather than automator as AppleScript was simple to implement. Also, as I used sudo and did not override the password prompt, I wanted to interact with the script.
- Open AppleScript Editor and create a new document in a location you can remember
- Paste these lines into the editor using the location and name of the shell script you created.
- The window will look like this:
- Save as an application
- Open Settings -> Users and click on Login items and then +
- Select your AppleScript application and click Add
- Close Settings, reboot and test. You will know your ramdisk is working if you see browser cache directories growing and changing as you open and use your browser.
- This is my first go at this automation, so if you have improvements, feel free to note them in the comments or contact me directly.