Screen Sharing application can't connect for 5 minutes after target Mac rebooted (Sequoia 15.3.1)

I've been networking 2 Mac Mini's, one of which is essentially using a "headless" configuration. When I use Screen Sharing to connect to the headless Mac, the connection fails until about 5 minutes from the time that the target machine has rebooted. Any ideas/workarounds to allow the Screen Sharing application to connect more quickly?


BTW, the target Mac is a Mac mini (2018) which uses the T2 security chip.


- Pie Lover

Mac mini (M2, 2023)

Posted on Mar 6, 2025 9:11 AM

Reply
4 replies
Sort By: 

Mar 7, 2025 12:49 PM in response to BlueberryLover

This actually may be the expected behaviour given that it may take some time for the Bonjour advertisements of the VNC screen sharing service to propagate across the local network.


- Pie Lover


Here is part of an Automator workflow to launch a screen sharing session (and then minimize its window):


on run {input, parameters}
	
	do shell script "open 'vnc://Media Server._rfb._tcp.local?quality=adaptive&numVirtualDisplays=0'"
	delay 20
	set hideApps to {"Screen Sharing"}
	
	try
		tell application "System Events"
			
			repeat with x in (get name of processes whose visible is true)
				if hideApps contains x then set visible of process x to false
			end repeat
			
		end tell
	end try
	
end run

Reply

Mar 13, 2025 6:31 AM in response to BlueberryLover

The following AppleScript command can be run (on the machine originating the connect) to confirm that the Screen Sharing connection has been established:

do shell script "lsof -a -i :vnc-server -sTCP:ESTABLISHED | grep rfb"


When Screen Sharing is successful, the command returns output similar to the following:

"Screen    740 admin    5u  IPv6 0x4fe2fb5a392e9c      0t0  TCP mac1.local:49182->mac2.local:rfb (ESTABLISHED)"


If not successful, it will throw an error:

error "The command exited with a non-zero status." number 1


- Pie Lover



Reply

Mar 18, 2025 6:21 AM in response to BlueberryLover

Below is an AppleScript routine (called from an Automator workflow) which is used to launch a screen sharing session on Media Server. It requires modification to be used in other setups.


- Pie Lover


on run {input, parameters}
	
	try
		do shell script "ping -c 1 -t 1 media-server.local"
	on error
		display dialog "Media Server not available" giving up after 5
		return
	end try
	
	
	try
		do shell script "lsof -a -i :vnc-server -sTCP:ESTABLISHED | grep rfb"
		
		set thedialog to display dialog "Maximize Screen Sharing window?" giving up after 5
		
		if button returned of thedialog = "OK" then
			tell application "Screen Sharing"
				activate
			end tell
		end if
		
		return
		
	on error
		
	end try
	
	
	do shell script "killall -HUP mDNSResponder" user name "admin_account" password "admin_password" with administrator privileges
	do shell script "open 'vnc://Media Server._rfb._tcp.local?quality=adaptive&numVirtualDisplays=0'"
	
	repeat 5 times
		delay 5
		tell application "System Events"
			if exists (window 1 of process "Screen Sharing") then
				if name of (window 1 of process "Screen Sharing") = "Media Server" then
					exit repeat
				end if
			end if
		end tell
	end repeat
	
	try
		do shell script "lsof -a -i :vnc-server -sTCP:ESTABLISHED | grep rfb"
		tell application "System Events"
			set visible of process "Screen Sharing" to false
		end tell
		
		delay 1
		set thedialog to display dialog "Maximize Screen Sharing window?" giving up after 5
		
		if button returned of thedialog = "OK" then
			tell application "System Events" to tell process "Screen Sharing"
				set value of attribute "AXFullScreen" of window 1 to true
			end tell
		end if
		
	on error
		
	end try
	
end run
Reply

Screen Sharing application can't connect for 5 minutes after target Mac rebooted (Sequoia 15.3.1)

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.