Screen Sharing – Screen Sharing Turned Off but Appears as Enabled on macOS

macosscreen-sharing

I used this command to disable screen sharing:

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

But when I try to confirm if it's disabled using the following, I get "enabled"

[[ -f /etc/com.apple.screensharing.agent.launchd ]] && echo 'enabled' || echo 'disabled'

Am I misunderstanding something? I would like to turn screen sharing off, and confirm that it is off.

Best Answer

Your shell script code is simply a check for the presence of the file /etc/com.apple.screensharing.agent.launchd. If the file is present, it prints enabled, else it prints disabled.

However, this file is always present (in 10.13 and possibly under 10.12 as well) whether the screensharing agent is currently active or not. Watchfiles in launchd are not necessarily checked for their presence or non-presence (unlike pidfiles in Linux, for example). Changes and updates to the file can also trigger actions.

It's probably best to rely on launchctl's actual facilities for introspection, via sudo launchctl list or the newer launchctl print system commands, rather than checking for the presence of legacy files.