1

我正在使用 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

但它仍然没有给我想要的结果。

我的问题是,有没有我可以写的行可以在执行此过程时隐藏窗口?谢谢。

4

1 回答 1

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 替换为当前用户的密码,即必须是管理员。

于 2013-08-08T18:22:08.457 回答