Reputation: 1015
I am using AppleScript to create a script that will turn on "Remote Login" in the System Preferences without the actual window opening.
Below is my code that is working but still opens the System Preferences window, therefore I can see exactly what it is doing:
tell application "System Preferences" to launch
tell application "System Preferences" to set current pane to pane "com.apple.preferences.sharing"
tell application "System Events" to set visible of process "System Preferences" to false
tell application "System Events" to tell process "System Preferences"
click checkbox 1 of row 5 of table 1 of scroll area 1 of group 1 of window "Sharing"
tell application "System Preferences"
quit
end tell
end tell
I have tried various lines such as:
tell application "System Events" to set visible of process "System Preferences" to false
but it still doesn't give me the result I want.
My question is, is there a line(s) I can write that can hide the window while it does this process? Thanks.
Upvotes: 1
Views: 453
Reputation: 1892
You can avoid to open System Preferences, you can start ssh (Remote Login) from the shell, so the AppleScript command will be:
do shell script "launchctl load -w /System/Library/LaunchDaemons/ssh.plist" user name (short user name of (system info)) password "currentuserpasssord" with administrator privileges
replace the currentuserpassword with the password of the current user, that is required to be an administrator.
Upvotes: 1