Screen Sharing via command?

PhillyPhoto
Valued Contributor

So, I guess in the past people were able to get Screen Sharing working via:

launchctl load -w /System/Library/LaunchAgents/com.apple.screensharing.agent.plist

That doesn't work in at least 10.11 or 10.12. If I run it twice in a row, the second time it says that the service is already running. The checkbox in Sharing isn't checked though, and attempting to connect via SS fails. If I unload it, and check off the checkbox in Sharing and the load it, I don't get the error. This leads me to believe that the two aren't actually connected in any meaningful way.

Also running the following has no effect:

/usr/libexec/PlistBuddy -c 'Set :com.apple.screensharing:Disabled NO' /private/var/db/launchd.db/com.apple.launchd/overrides.plist

Running Composer for changes doesn't pick anything up related to screen sharing.

Has anyone gotten Screen Sharing working on 10.11+ via command without enabling Remote Management?

5 REPLIES 5

emily
Valued Contributor III
Valued Contributor III

A quick Google brought up this: sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -activate -configure -access -on -configure -allowAccessFor -allUsers -configure -restart -agent -privs -all (All users, not the best idea, but a starting point with a testing machine. Source.)

Maybe try that?

Nix4Life
Valued Contributor

Take a look here, perhaps that may help

PhillyPhoto
Valued Contributor

I'm trying to enable only Screen Sharing and not Remote Management.

cnorrisAdmin
New Contributor III

I have been using this script for a few years and it still works for the current OS versions:

!/bin/sh

write stdout and stderr to /Library/Logs/AdminScript.log

exec >> "/Library/Logs/AdminScript.log" 2>&1

Last modified December 6, 2016

DATE=date "%A %m/%d/%Y %H:%M"
echo " $0 " date "
%A %m/%d/%Y %H:%M:%S" " "

set variables

Kickstart="/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart"
UsersCreated=(techuser adminuser)
GenericPW='password'

echo "=========== Create Administrative Accounts ============"

Enables Hide500Users to allow hiding accounts

echo "enable hiding accounts from login and fast user switching menu…"
if [[ $(defaults read /Library/Preferences/com.apple.loginwindow Hide500Users) != 1 ]]; then echo "The Hide500Users option is Disabled. Changing to Enabled..." defaults write /Library/Preferences/com.apple.loginwindow Hide500Users -bool TRUE
else echo "The Hide500Users option is already Enabled"
fi

Checks to see if the SSH access list exists, if not, it is created

if [[ $(dseditgroup com.apple.access_ssh) = "Group not found." ]]; then echo "The com.apple.access_ssh group does not exist, so it is being created." dseditgroup -o create com.apple.access_ssh
else echo "The com.apple.access_ssh group already exists."
fi

Checks to see if each account exists, if not, uses the jamf binary to create the account,

home folder in /private/var, assign the same RealName, and add the account to the SSH access list

for i in ${UsersCreated[@]}
do if [[ $(id -F "$i") = "$i" ]] then echo "The $i account already exists, adding to the SSH access list..." dseditgroup -o edit -a $i -t user com.apple.access_ssh else echo "Creating the $i account..." /usr/local/jamf/bin/jamf createAccount -username $i -realname $i -password $GenericPW -home /private/var/$i -hiddenUser -admin echo "adding the $i account to the SSH access list..." dseditgroup -o edit -a $i -t user com.apple.access_ssh fi
done

Adds the Admin group to ssh remote access group

dseditgroup -o edit -a admin -t group com.apple.access_ssh

sets the proper permissions for ARD access

echo "Remote access will now be configured for proper Getty access"
$Kickstart -activate
$Kickstart -configure -allowAccessFor -specifiedUsers
$Kickstart -configure -users techuser,adminuser -access -on -privs -all -clientopts -setreqperm -reqperm yes

Displays the Admin group membership and the ssh remote access list

echo ""
echo "This is the admin group membership:"
dscl . -read /Groups/admin GroupMembership | grep GroupMembership | cut -c 18-
echo ""
echo "This is the SSH access list:"
dscl /Local/Default read Groups/com.apple.access_ssh | grep GroupMembership | cut -c 18-

echo " $0 Completed" date "+%A %m/%d/%Y %H:%M:%S" " *"

exit 0

PhillyPhoto
Valued Contributor

Looking to just enable Screen Sharing looks like it can be done via AppleScript:

tell application "System Preferences"
    activate
    set the current pane to pane id "com.apple.preferences.sharing"
end tell

tell application "System Events"
    tell process "System Preferences"
        tell window "Sharing"
            delay 0.5
            click checkbox 1 of row 1 of table 1 of scroll area 1 of group 1
            delay 0.125
            keystroke tab
            delay 0.125
            keystroke tab
            delay 0.125
            keystroke tab
            delay 0.125
            keystroke tab
            delay 0.125
            keystroke tab
            delay 0.125
            key code 126
            delay 0.5
        end tell
    end tell
end tell

tell application "System Preferences" to quit

The only problem with this is, you have to allow "installd" under Security & Privacy > Privacy > Accessibility.