Created
November 12, 2022 22:06
-
-
Save mcculley/f970ee57e5b901533be6d89b1b8921e7 to your computer and use it in GitHub Desktop.
This file contains 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 | |
# This is a tool to control contactsd on macOS. For some reason, contactsd | |
# consumes a lot of CPU when running against my (large, 9,779 entry) | |
# addressbook. I think contactsd is responsible for synchronizing the | |
# addressbook in the background, but it makes my local instance of the Contacts | |
# app hang and burns up my battery. So I stop contactsd when I use the Contacts | |
# app and then restart it to allow the sync to happen. However, modern macOS | |
# will not allow one to stop the contactsd launch agent to be disabled. System | |
# Integrity Protection will not allow one to disable it. So what I really do is | |
# send the process a SIGSTOP signal to make it hang. Then I just restart it | |
# when I really want to start it. | |
case $1 in | |
start) | |
echo "starting contactsd" | |
launchctl stop com.apple.contactsd && launchctl start com.apple.contactsd | |
;; | |
stop) | |
echo "stopping contactsd" | |
# Get the PID of the running contactds process | |
CPID=$(launchctl list |grep com.apple.contactsd|cut -d$'\t' -f1) | |
# Send a SIGSTOP to the process to hang it. If we kill it, launchd will | |
# just restart it. | |
kill -SIGSTOP $CPID | |
;; | |
*) | |
echo "unknown command:" $1 | |
echo "use start or stop" | |
exit 1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment