1

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.

  • Why don't you just look in System Prefs/Sharing & toggle it there? Would save several layers of guesswork. – Tetsujin Oct 13 '17 at 17:31
  • I did, it appears off, but I am trying to figure out why it appears as "enabled" via the command in the op. – user259589 Oct 13 '17 at 18:00
  • As an amateur in other languages, I'd be suspicious of && something || something - but my coding chops aren't good enough to know if I'm right or wrong, sorry. – Tetsujin Oct 13 '17 at 18:19
1

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.

You must log in to answer this question.