我正在使用AppleScript创建一个脚本,该脚本将在系统偏好设置中启用“远程登录”,而不会打开实际窗口。
下面是我的代码正在运行,但仍会打开“系统偏好设置”窗口,因此我可以看到它正在做什么:
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
我尝试了各种各样的行,例如:
tell application "System Events" to set visible of process "System Preferences" to false
但它仍然没有给我我想要的结果。
我的问题是,我可以编写一行可以在执行此过程时隐藏窗口吗?感谢。
答案 0 :(得分:1)
您可以避免打开系统偏好设置,可以从shell启动ssh(远程登录),因此AppleScript命令将为:
do shell script "launchctl load -w /System/Library/LaunchDaemons/ssh.plist" user name (short user name of (system info)) password "currentuserpasssord" with administrator privileges
将currentuserpassword替换为当前用户的密码,该密码需要是管理员。