Skip to content

Instantly share code, notes, and snippets.

@chris1111
Created July 20, 2019 01:53
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chris1111/30b9123a6d06864c0fe34666a107f72b to your computer and use it in GitHub Desktop.
Save chris1111/30b9123a6d06864c0fe34666a107f72b to your computer and use it in GitHub Desktop.
Enable or Disable the Trim in macOS Catalina 10.15
#!/bin/bash
# Simple script by chris1111
# Vars
apptitle="Trim Enabler Catalina"
version="1.0"
# Set Icon directory and file
iconfile="/System/Library/CoreServices/Expansion Slot Utility.app/Contents/Resources/AppIcon.icns"
# Select Trim Choice
response=$(osascript -e 'tell app "System Events" to display dialog "Enable or Disable the Trim in macOS Catalina\n\nCancel for Exit" buttons {"Enable","Disable","Cancel"} default button 1 with title "'"$apptitle"' '"$version"'" with icon POSIX file "'"$iconfile"'" ')
action=$(echo $response | cut -d ':' -f2)
# Action is user select Disable
if [ "$action" == "Disable" ] ; then
response=$(osascript -e 'tell app "System Events" to display dialog "Your Choice is Disable Trim Enabler Catalina\n\n" buttons {"Cancel","OK"} default button 2 with title "'"$apptitle"' '"$version"'" with icon POSIX file "'"$iconfile"'" ')
answer=$(echo $response | grep "OK")
# Cancel if unable
if [ ! "$answer" ] ; then
echo "Program closing User cancelled
Exit"
exit 012345
fi
sudo mount -uw /
killall Finder
sudo trimforce disable
exit 0
fi
# Action is user select Enable
if [ "$action" == "Enable" ] ; then
response=$(osascript -e 'tell app "System Events" to display dialog "Your Choice is Enable Trim Enabler Catalina\n\n" buttons {"Cancel","OK"} default button 2 with title "'"$apptitle"' '"$version"'" with icon POSIX file "'"$iconfile"'" ')
answer=$(echo $response | grep "OK")
# Cancel if unable
if [ ! "$answer" ] ; then
echo "Program closing User cancelled
Exit"
exit 012345
fi
sudo mount -uw /
killall Finder
sudo trimforce enable
exit 0
fi
# Cancel is user selects Cancel
if [ ! "$imagepath" ] ; then
echo "Program closing User cancelled
Exit"
exit 012345
fi
@chris1111
Copy link
Author

See Choice Enable

Capture d’écran, 1-EN
Capture d’écran, 2-EN

@driscollxy
Copy link

driscollxy commented Oct 13, 2019

First of all, thank you for your script.
After run script, I found it has issue on sudo mount -uw /:
./trim_enable.sh
Password:
mount_apfs: volume could not be mounted: Operation not permitted
mount: / failed with 77
IMPORTANT NOTICE: This tool force-enables TRIM for all relevant attached
devices, even though such devices may not have been validated for data
integrity while using TRIM. Use of this tool to enable TRIM may result in
unintended data loss or data corruption. It should not be used in a commercial
operating environment or with important data. Before using this tool, you
should back up all of your data and regularly back up data while TRIM is
enabled. This tool is provided on an “as is” basis. APPLE MAKES NO WARRANTIES,
EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF
NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE,
REGARDING THIS TOOL OR ITS USE ALONE OR IN COMBINATION WITH YOUR DEVICES,
SYSTEMS, OR SERVICES. BY USING THIS TOOL TO ENABLE TRIM, YOU AGREE THAT, TO THE
EXTENT PERMITTED BY APPLICABLE LAW, USE OF THE TOOL IS AT YOUR SOLE RISK AND
THAT THE ENTIRE RISK AS TO SATISFACTORY QUALITY, PERFORMANCE, ACCURACY AND
EFFORT IS WITH YOU.
Are you sure you wish to proceed (y/N)?

@chris1111
Copy link
Author

Do you have a Core Storage Volume?

@driscollxy
Copy link

Do you have a Core Storage Volume?

No, I have no CoreStorage.
I list using diskutil cs list shows 2 external disks (no Macintosh HD in the list).

@chris1111
Copy link
Author

I use and test / Built the script with SIP Disable

@driscollxy
Copy link

I use and test / Built the script with SIP Disable

Oh, I got it. Thank you for your answer about SID Disable. This case I'm ok to ignore mount: / failed with 77 for MacOS is SIP Enable.

BR,
Jeans

@kimsyversen
Copy link

Worked for me on 10.15.2.

@chris1111
Copy link
Author

Worked for me on 10.15.2.

Great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment