Code/new purgeVM

From kJams Wiki
Jump to navigation Jump to search

If you are having problems with losing disk space on OSX due to swap file space growing out of control, you can solve the issue by rebooting.

Alternately, if you are not afraid of venturing into Terminal land, you can use this tiny little app I wrote, which will purge unused RAM cache and collapse and remove unused swap space, potentially dramatically restarting "missing" disk space and restoring system performance.

Be VERY careful, however, as setting it up involves doing things that could potentially render your system unbootable. (If what I am writing seems unintelligible to you, it might be best for you not to attempt it!)

sudo purge
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.dynamic_pager.plist
sudo rm /private/var/vm/swapfile*
sudo launchctl load -wF /System/Library/LaunchDaemons/com.apple.dynamic_pager.plist

Open a text editor and paste in the code. Save somewhere. Then go to Terminal. Log in to an administrator account and type "chmod 755 path/to/the/file". Now you can double click on it, and it will open Terminal, run the code, and exit. You need to make sure you are either running this from an admin account, or add your standard user account to sudoers for this to work.

To add your standard account to sudoers, log in to an admin account, type "sudo visudo" and type in your admin password. Find the following line:

# User privilege specification
root    ALL=(ALL) ALL
%admin  ALL=(ALL) ALL

and add your standard user account info like this:

# User privilege specification
root    ALL=(ALL) ALL
%admin  ALL=(ALL) ALL
yourshortusername     All=(ALL) ALL

Alternately, you can run AppleScript Editor, and paste the following code into a new script:

do shell script "sudo purge
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.dynamic_pager.plist
sudo rm /private/var/vm/swapfile*
sudo launchctl load -wF /System/Library/LaunchDaemons/com.apple.dynamic_pager.plist
" with administrator privileges

Save as an application by selecting "Save…" from the File menu then selecting "Application" from the "File format" pop up menu.

Now you can just double click and run like any normal OSX app.