Created
August 25, 2025 16:18
-
-
Save majick/7d3dad72d32631e1712cf08736393caa to your computer and use it in GitHub Desktop.
uninstall macOS packages safely
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # safely and noiselessly uninstall macos packages | |
| # | |
| # to see packages installed: | |
| # pkgutil --pkgs | |
| rmdir-if-exist() { | |
| # ghetto only first parameter | |
| [[ -d "$1" ]] && sudo rmdir --ignore-fail-on-non-empty "$1" | |
| } | |
| export -f rmdir-if-exist | |
| pkgutil --only-files --files $PACKAGE | tr '\n' '\0' | xargs -n 1 -0 sudo rm -f \ | |
| && pkgutil --only-dirs --files $PACKAGE | /usr/bin/tail -r | tr '\n' '\0' | xargs -0 -I "{}" bash -c 'rmdir-if-exist "{}"' \ | |
| && sudo pkgutil --forget $PACKAGE | |
| # DESCRIPTION: | |
| # based on https://gist.github.com/githubutilities/b5318d08a4b970d104f1 | |
| # but not as failure-prone, ghetto, or manual | |
| # BUGS: Slow as fuck | |
| # JANK: I use gnu utilities because bsd userland is a barely-working plague, | |
| # but reversed tail is a bsd thing so we call it by path | |
| # LICENSE: Released to the Public Domain without copyright | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment