Steps:
- Create an AppleScript, e.g. /Users/eddiecjc/Documents/Scripts/RamDisk.scpt
set isTmpDiskRunning to "false" set isRamdiskCreated to "false" tell application "Finder" if not (exists POSIX file "/Volumes/Ramdisk") then -- Method 1, may have problem with system hibernate. -- Creating RamDisk, with size 4GB (4 * 1024 * 1024 * 2) do shell script "diskutil erasevolume HFS+ RamDisk `hdiutil attach -nomount ram://$((4*1024*1024*2))`" -- Method 2, using Open Source software TpmDisk. --do shell script " -- open -a /Applications/TmpDisk.app --args -name=RamDisk -size=4096 -- " --set isTmpDiskRunning to "true" end if repeat until isRamdiskCreated = "true" if exists POSIX file "/Volumes/Ramdisk" then set isRamdiskCreated to "true" else display alert "Ramdisk is NOT created. Retry in 5 seconds..." as critical buttons {"I will wait"} giving up after 5 end if end repeat end tell -- Create Folders set FolderPath to POSIX file "/Volumes/Ramdisk" as alias tell application "Finder" try make new folder at FolderPath with properties {name:"Library Caches"} make new folder at FolderPath with properties {name:"Downloads"} make new folder at FolderPath with properties {name:"Temp"} make new folder at (POSIX file "/Volumes/Ramdisk/Temp" as alias) with properties {name:"Screenshots"} -- Set up symbolic link --sudo rm -r ~/Library/Caches --ln -s /Volumes/RamDisk/Library\ Caches ~/Library/Caches --sudo rm -r ~/Downloads --ln -s /Volumes/RamDisk/Downloads ~/Downloads -- Change screenshots default location -- defaults write com.apple.screencapture location /Volumes/Ramdisk/Temp/Screenshots -- killall SystemUIServer end try end tell if isTmpDiskRunning = "true" then -- Kill the process, so it does not take up the space from the task bar. set app_name to "TmpDisk" do shell script "killall " & app_name end if -- 1. Export this to type Application RamDisk.app. -- 2. Mark as Run-Only -- 3. Mark the file as executable with chmod +x
. -- 4. Add RamDisk.app to Login Items in the Users & Groups. - Export the script to type Application, e.g. /Users/eddiecjc/Documents/Scripts/RamDisk.app, and mark it as Run-Only
-
In Terminal, mark the file as executable, e.g.
chmod +x /Users/eddiecjc/Documents/Scripts/RamDisk.app
- Add the script to run during start up
- Open System Preferences
- Go to Users & Groups
- Select the current user
- Go to Login Items tab
- Click on "+" and navigate to the RamDisk.app
- Repeat for other users that would need a RamDisk
- Run RamDisk.app to set up the RamDisk as a preparation for the remaining steps.
-
Move stuff to Ramdisk:
- Move ~/Library/Caches to Ramdisk
sudo rm -r ~/Library/Caches ln -s /Volumes/RamDisk/Library\ Caches ~/Library/Caches
- Move Downloads to Ramdisk
sudo rm -r ~/Downloads ln -s /Volumes/RamDisk/Downloads ~/Downloads
- Move screenshot default saving location to Ramdisk
Reference: http://simonemccallum.com/2013/08/11/how-to-change-the-default-location-for-your-mac-os-x-screenshots/defaults write com.apple.screencapture location /Volumes/Ramdisk/Temp/Screenshots killall SystemUIServer
- Change any default download location for apps (e.g. Chrome)
- Change the unarchiver default working directory.
- Move ~/Library/Caches to Ramdisk
- If using the built-in command rather than TmpDisk, for laptops, change the hibernation mode, to prevent Ramdisk being ejected after hibernation.
-
Find out the current hibernation mode:
Default is 3 for laptops, indicating contents in the Ram will be written to the hard drive before going to hibernate mode.pmset -g | grep hibernatemode
- Change it to 0, so battery will still power the Ram (drawback is that if the battery is drained or power is lost, then resuming from hibernation would fail):
sudo pmset -a hibernatemode 0
- Clean the disk space used previously for the hibernation:
Reference: http://blog.roodo.com/jason1204/archives/25384258.html and http://etherealmind.com/osx-hibernate-mode/cd /var/vm sudo rm sleepimage
- Restart the Mac, Ramdisk should be created after log in.
Note: Mac OS X comes with built-in command to create virtual disks using ram, as described above, but there is a problem of Ramdisk disappearing after the hibernation. To get around this issue, there is an Open Source ramdisk tool called TmpDisk, download and install TmpDisk from http://inkscribbles.com/apps/tmpdisk/. Comment out method 1 in the script and uncomment to use method 2 instead.
Thank you. This has completely solved my Spotify performance problems. It used to take 2 minutes to start up and load all panels, now it only takes 15 seconds!
回覆刪除For method 2, I found I had to change
open -a /Applications/TmpDisk.app --args -name=RamDisk -size=4096
to
open -a /Applications/TmpDisk.app/Contents/MacOS/TmpDisk --args -name=RamDisk -size=4096