Automator Or AppleScript To Turn On/Off Screen Sharing

I want to use AppleScript To Turn On/Off Screen Sharing with a double-click. I have searched for, and, discovered some examples, however, being several years old, they don’t work with El Capitan.

Any suggestions?

Thank you.

Hi,

On:

do shell script "launchctl load -w /System/Library/LaunchDaemons/com.apple.screensharing.plist" with administrator privileges

Off:

do shell script "launchctl unload -w /System/Library/LaunchDaemons/com.apple.screensharing.plist" with administrator privileges

Hello, StefanK.

Thank you for your prompt response.

Nice work.

I ran another test, after I removed

with administrator privileges

from your code, because I want to change the state of Screen Sharing, with a double-click only. Unfortunately, and predictably, the script does not function properly.

Is there a method to change the state of Screen Sharing, without prompting for User password?

My ultimate objective is to automatically turn on Screen Sharing at the same time, every morning, and, to automatically turn off Screen Sharing at the same time, every night.

Thank you.

Kurt

You can pass the the password

do shell script "launchctl load -w /System/Library/LaunchDaemons/com.apple.screensharing.plist" password "mypass" with administrator privileges

The alternative is to GUI script System Preferences which is ugly.

Hi, StefanK.

Your code works wonderfully! Again, thank you.

I have assigned a Calendar Alert to launch the script (Exported as an App.), however, the Event loses the Alert when I click Apply. My research has revealed that the Alert Event must be on my computer, not on my iCloud account. This is unfortunate, since I want Calendar to launch the scripts on both of my iMacs (home and office). I don’t want to create this Alert Event “On My Computer” on both iMacs. This defeats the purpose of cloud synchronization.

I am unable to create a new “On My Computer” account in Calendar.

Kurt