Trim for third party Solid State Drives in Mac OSX.

Trim is a command that is executed in the background by the operative system when you delete files, informing the SSD that the blocks are no longer in use and can be deleted. By doing this, the SSD can avoid slowing down future write operations to those blocks. Below are the terminal commands used to do this. If that fails you can download software called Trim Enabler, the link is below. It’s free but I would ask that you donate to the developer.

TRIM can be enabled by using the following Terminal commands. Copy these commands and run them in Terminal:

Backup the file that you’re about to patch:

sudo cp /System/Library/Extensions/IOAHCIFamily.kext/Contents/ PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/ IOAHCIBlockStorage /IOAHCIBlockStorage.original

Patch the file to enable TRIM support: 

sudo perl -pi -e ‘s|(\x52\x6F\x74\x61\x74\x69\x6F\x6E\x61\x6C \x00).{9}(\x00\x51)|$1\x00\x00\x00\x00\x00\x00\x00\x00\x00$2| sg’ /System/Library/Extensions/IOAHCIFamily.kext/Contents/ PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/ IOAHCIBlockStorage

Clear the kext caches: 

sudo kextcache -system-prelinked-kernel
sudo kextcache -system-caches

Important: reboot your Mac!
To disable TRIM support in the future: 

sudo perl -pi -e ‘s|(\x52\x6F\x74\x61\x74\x69\x6F\x6E\x61\x6C \x00).{9}(\x00\x51)|$1\x41\x50\x50\x4C\x45\x20\x53\x53\x44$2| sg’ /System/Library/Extensions/IOAHCIFamily.kext/Contents/ PlugIns/IOAHCIBlockStorage.kext/Contents/MacOS/ IOAHCIBlockStorage

Finally, if this does not work as expected, or if something goes wrong, simply restore the backup: 

sudo cp /IOAHCIBlockStorage.original /System/Library/ Extensions/IOAHCIFamily.kext/Contents/PlugIns/ IOAHCIBlockStorage.kext/Contents/MacOS/IOAHCIBlockStorage

This patch simply edits a file called IOAHCIBlockStoage, removing a string that makes TRIM work for only Apple SSDs.