Apple Remote Desktop Refuse to Connect Trick

Sometimes Apple’s Remote Desktop does not work as expected, meaning when a remote Mac has been correctly configured and could be connected before, starts to fail when initiating the “control” request. A popup connection window would take forever and finally tells the user it cannot connect to the remote Mac. This would cause tremendously obstacles when user’s workflow relies heavily on the remote Mac server, whether the Mac server is deployed at home, office, being a file server or managing emails in the background.

Perhaps the first thing that comes to your mind is to restart the remote server, it works initially, but later on the refuse to connect would appears out of no where.

In this post, I will show a simple trick that you could try and see if it could solve the refuce to connect issue. There could be multiple solutions and this one may not be the correct one, but I hope that you could give it a shot.

So there is a process on the remote server that controls how the remote deskop is being connected: /System/Library/CoreServices/RemoteManagement/ScreensharingAgent.bundle/Contents/MacOS/ScreensharingAgent, so what you want to do one way is to kill this process, but don’t worry, there’s a launch agent that would help you to maintain the process, that launch agent is located in /System/Library/LaunchAgents/com.apple.screensharing.agent.plist.

Here is what it looks like for the plist file, it would be another topic for diving into Launch Agents and Launch Daemons, for Windows, you could think of this as services and Linux there’s. systemd that helps you to maintain and run code.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>ProcessType</key>
	<string>Interactive</string>
	<key>EnableTransactions</key>
	<true/>
	<key>Label</key>
	<string>com.apple.screensharing.agent</string>
	<key>ProgramArguments</key>
	<array>
		<string>/System/Library/CoreServices/RemoteManagement/ScreensharingAgent.bundle/Contents/MacOS/ScreensharingAgent</string>
	</array>
	<key>MachServices</key>
	<dict>
		<key>com.apple.screensharing.agent</key>
		<true/>
	</dict>
	<key>RunAtLoad</key>
	<false/>
	<key>WatchPaths</key>
	<array>
		<string>/private/etc/com.apple.screensharing.agent.launchd</string>
	</array>
	<key>LaunchEvents</key>
	<dict>
		<key>com.apple.notifyd.matching</key>
		<dict>
			<key>com.apple.screensharing.agent</key>
			<dict>
				<key>Notification</key>
				<string>com.apple.screensharing.agent.launchd</string>
			</dict>
		</dict>
	</dict>
	<key>LimitLoadToSessionType</key>
	<array>
		<string>Aqua</string>
		<string>LoginWindow</string>
	</array>
	<key>ThrottleInterval</key>
	<integer>1</integer>
</dict>
</plist>
XML

What we want to do is to simply kill the process like this:

kill $(pgrep "ScreensharingAgent")
ShellScript

It would take a few seconds for the service to be restarted, and on the remote desktop, it should go back to normal, meaining you could access your Mac remotely using GUI.


Posted

in

by

Tags:

Comments

Leave a Reply

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