2

Is there a terminal command to determine if a screensharing session from a remote machine is not just initiated but also actively being viewed?

Details:

I have a background (Perl) process running on a remote machine that issues system commands like

netstat -n | grep 5900
ps aux | grep ScreensharinAgent

to verify that a Screensharing session has been initiated. Both of these commands return expected data the moment Screensharing authentication begins.

However, I'd also like the process to determine if the screen is successfully being viewed.

da4's comment here comes close but I can't/don't know how to modularize log stream --predicate 'eventMessage contains "Authentication"'.

Here's a modified version of the Perl snippet I'm working on

$owner = "owner"
$user = trim(`stat -f%Su /dev/console`);

while ($user eq $owner) {
my $user = trim(`stat -f%Su /dev/console`);
my %screensharing_processes = (
    "netstat -n | grep 5900" => "\.5900.*?ESTABLISHED",
    "ps aux | grep ScreensharingAgent" => "$user.*?ScreensharingAgent.bundle",
    "terminal_command_to_verify_screensharing" => "some_string_verifying_condition",
#   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  );
  while (($command, $value) = each (%screensharing_processes)) {
    my $this_process = `$command`;
    if ($this_process =~ /$value/s) {
      print "$value is up\n";
    } else {
      print "$value is down\n";
    }
  }
  print "\n";
  sleep 1;
}

sub trim {
  return $_[0] =~ s/^\s+|\s+$//rg;
}

Is there a terminal command which the remote machine's background process can issue to determine if the screensharing session is not just initiated but also actively being viewed?

For obvious reasons, solutions like the accepted one in the question I mentioned won't work here.

You must log in to answer this question.

Browse other questions tagged .