#!/usr/bin/env bash set -euo pipefail open_settings=false while [[ $# -gt 0 ]]; do case "$1" in --open-settings) open_settings=true shift ;; *) printf "Unknown option: %s\n" "$1" >&2 exit 1 ;; esac done screen_sharing_enabled() { launchctl print system/com.apple.screensharing >/dev/null 2>&1 } vnc_listening() { nc -z 127.0.0.1 5900 >/dev/null 2>&1 } remote_management_enabled() { launchctl print system/com.apple.RemoteDesktop.agent >/dev/null 2>&1 } write_step() { local label="$1" status="$2" printf "[%s] %s\n" "$status" "$label" } printf "AllReach macOS Screen Sharing host preparation\n" printf "Mode: check only\n\n" if screen_sharing_enabled; then write_step "Screen Sharing service" "OK" elif remote_management_enabled; then write_step "Remote Management service" "OK" else write_step "Screen Sharing or Remote Management" "CHANGE" fi if vnc_listening; then write_step "TCP 5900 listener" "OK" else write_step "TCP 5900 listener" "CHECK" printf " Listener appears after Screen Sharing or Remote Management is enabled.\n" fi printf "\nNo settings were changed.\n" printf "To enable hosting manually: System Settings > General > Sharing > Screen Sharing.\n" if [[ "$open_settings" == true ]]; then open "x-apple.systempreferences:com.apple.preferences.sharing" fi