Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I want to be able to enable and disable screen sharing from the command line rather than through System Preferences. This is on 10.8.3

To enable screen sharing, I find I only need to change a dictionary value in the following plist:

/var/db/launchd.db/com.apple.launchd/overrides.plist

To be precise, to enable screen sharing, I do the following:

sudo defaults write /var/db/launchd.db/com.apple.launchd/overrides.plist com.apple.screensharing -dict Disabled -bool false

And that changes:

sudo defaults read /var/db/launchd.db/com.apple.launchd/overrides.plist com.apple.screensharing
{
    Disabled = 1;
}

To:

sudo defaults read /var/db/launchd.db/com.apple.launchd/overrides.plist com.apple.screensharing
{
    Disabled = 0;
}

Fine. I see from this site that I need to then do this (not sure why):

sudo launchctl load /System/Library/LaunchDaemons/com.apple.screensharing.plist

Now if I want to disable screen sharing I try the reverse:

sudo defaults write /var/db/launchd.db/com.apple.launchd/overrides.plist com.apple.screensharing -dict Disabled -bool true

I get:

sudo defaults read /var/db/launchd.db/com.apple.launchd/overrides.plist com.apple.screensharing
{
    Disabled = 1;
}

Which is good, but then I have no successful way to get launchctl, or whatever (not really sure) to re-read this plist.

I try

sudo launchctl load /System/Library/LaunchDaemons/com.apple.screensharing.plist

and I get:

nothing found to load

And indeed, despite the dictionary value for this screen sharing being properly set to indicate screen sharing should be off, well, I still can screen share in just fine.

So what is the proper way to disable screen sharing from the command line on 10.8.3?

share|improve this question
add comment

1 Answer

up vote 6 down vote accepted

To start screensharing:

sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.screensharing.plist

To stop:

sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.screensharing.plist

The -w flag modifies the Disabled key as appropriate. It's best to let launchctl handle this, as the location where the config files are stored has changed a bit between OS versions.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.