End Screensharing Sessions via Apple Script + Countdown in a PopUp Win

Hey there,

i am currently trying to write a script that will end all currently active screensharing sessions plus set the mac to sleep withing 10 seconds.

Until now i only got the delayed sleep but not the disconnecting of those active screensharing sessions.

This is the script:

# time in seconds to delay before sleep
set delay_time to 10

display dialog ¬
	"Going to sleep in " & delay_time & ¬
	" seconds" buttons {"Cancel"} ¬
	giving up after delay_time ¬
	default button 1
copy the result as list to {buttonpressed}
if the buttonpressed is not "Cancel" then
	tell application "Finder" to sleep
end if

Is there a way to tell the mac to disconnect all screensharing sessions?

I also would like to have the seconds count down when displayed in this popup windows (currently you will only see “Going to sleep in 10 seconds” without the 10 changing to 9,8,7…)

Thank you very much!


try this

# time in seconds to delay before sleep
set delay_time to 10

repeat with i from delay_time to 0 by -1
	display dialog "Going to sleep in " & (i as text) & ¬
		" seconds" buttons {"Cancel"} ¬
		giving up after 1 ¬
		default button 1
end repeat
set screenSharingPath to (path to library folder from system domain as text) & "CoreServices:Screen Sharing.app"
quit application screenSharingPath
tell application "Finder" to sleep

thx, the countdown is now working :slight_smile:

Whats not working is the screensharing problem. The thing is that there is no screensharing.app running on the server i connect to. Its just an unknown process in the menubar :frowning:

I also was puzzled about how to shut down screen sharing as there is no *.app. But, I found that I could do something like this:

tell application "Screen Sharing"
end tell

Hopes this helps.