system/com.apple.screensharing fix

After installing OpenCore Legacy Patcher on my Mac mini, it has been flawlessly running Monterey for several months, with the exception that screensharing stops randomly. To get around this, I’ve been making an ssh connection to the Mac mini and then run this command:

sudo launchctl kill KILL system/com.apple.screensharing

Rather than having to run this command manually, automate it with launchctl to run as a LaunchDaemon every day at 2 am:

  1. Touch a .plist file in the following directory using this command in Terminal:
    sudo touch /Library/LaunchDaemons/com.screensharing.restart.plist
  2. Edit the .plist file by executing this command in Terminal:sudo pico com.screensharing.restart.plist
  3. Copy text from this file and paste it into your .plist file.
  4. Save your .plist file by pressing the “control” and “x” keys and choose press “y” and “return”.
  5. Load the .plist into launchctl using the following command in Terminal.app:
    sudo launchctl load /Library/LaunchDaemons/com.screensharing.restart.plist
  6. If the LaunchDaemon loaded, it should appear in the list produced by this Terminal command:
    sudo launchctl list
  7. To unload the LaunchDaemon we created above, execute the following command in Terminal:
    launchctl unload /Library/LaunchDaemons/com.screensharing.restart.plist
  8. Finally, if you wish to completely remove this command from your machine, delete the .plist file with this command:
    sudo rm /Library/LaunchDaemons/com.screensharing.restart.plist

Worth noting, this LaunchDaemon executes as the “_www” user, so it should run whenever the Mac mini has booted Monterey. Will keep you posted how this works and if I need to increase the frequency. Ultimately, I’d like to find out what is causing the screensharing crash, but that may be above my abilities.

Leave a Reply

Your email address will not be published. Required fields are marked *