Skip to content

Instantly share code, notes, and snippets.

@kmahyyg
Created December 16, 2025 02:55
Show Gist options
  • Select an option

  • Save kmahyyg/163d7cb79b5ad0a6f1da8496f41ac2bb to your computer and use it in GitHub Desktop.

Select an option

Save kmahyyg/163d7cb79b5ad0a6f1da8496f41ac2bb to your computer and use it in GitHub Desktop.
MacOS Useful Troubleshooting Script
#!/bin/zsh
#
# Mac OS Commonly-Used Scripts
# Remove Quarantine of Apple Protection
function rm_applequa() {
sudo xattr -r -d com.apple.quarantine "${1}"
sudo xattr -r -d com.apple.provenance "${1}"
}
alias rm_applequa_dwnld=' rm_applequa ~/Downloads '
alias restart_desktop_widgets='pkill -9 NotificationCenter'
function resign_cracked() {
codesign --sign - --force --deep "${1}"
}
function after_mac_upgrade_xcode() {
softwareupdate --list
xcode-select --install
xcodebuild -runFirstLaunch
xcodebuild -checkFirstLaunchStatus
}
function why_tm_failed(){
log show --info --style compact --predicate '(subsystem == "com.apple.TimeMachine") && (eventMessage like[cd] "Failed * acquire device lock assertion*")' --last 24h
}
## The three functions listed below is used for diagnosing high CPU usage caused by spotlight.
## https://apple.stackexchange.com/questions/144474/mds-and-mds-stores-constantly-consuming-cpu
##
function spotlight_restart() {
sudo mdutil -v -i off /
sudo mdutil -v -i off /System/Volumes/Data
sudo mdutil -v -E /
sudo mdutil -v -E /System/Volumes/Data
sudo mdutil -v -i on /
sudo mdutil -v -i on /System/Volumes/Data
}
function why_spotlight_eat_cpu() {
sudo fs_usage -w mds
}
function read_spotlight_log() {
sudo log stream --style compact --level debug --process mds
}
# Silent Mac OS upgrade notification
function silent_mac_upgrade() {
defaults write com.apple.SoftwareUpdate MajorOSUserNotificationDate -date "2030-12-31 23:59:59 +0000"
defaults write com.apple.SoftwareUpdate UserNotificationDate -date "2030-12-31 23:59:59 +0000"
}
# Enable MetalFX HUD for display performance stats
function enable_metal_hud() {
/bin/launchctl setenv MTL_HUD_ENABLED 1
}
function disable_metal_hud() {
/bin/launchctl setenv MTL_HUD_ENABLED 0
}
function disable_userdir_share() {
sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server VirtualHomeShares -bool NO
sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server VirtualAdminShares -bool NO
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment