Authentication 在远程Mac上运行CGSession-switchToUserID

Authentication 在远程Mac上运行CGSession-switchToUserID,authentication,session,applescript,osascript,switch-user,Authentication,Session,Applescript,Osascript,Switch User,我的远程Mac上有下一个脚本: on run do shell script "/System/Library/CoreServices/Menu\\ Extras/User.menu/Contents/Resources/CGSession -switchToUserID 502" delay 5 tell application "System Events" keystroke "mypassword" & return de

我的远程Mac上有下一个脚本:

on run
    do shell script "/System/Library/CoreServices/Menu\\ Extras/User.menu/Contents/Resources/CGSession -switchToUserID 502"
    delay 5
    tell application "System Events"
        keystroke "mypassword" & return
        delay 4
        keystroke tab
        keystroke return
    end tell

end run
如果在通过VNC登录时(在cmd
osascript
中)运行该脚本,则该脚本工作正常,但在通过ssh运行时,该脚本不工作。我注意到只有
do shell script”/System/Library/CoreServices/Menu\\Extras/User.Menu/Contents/Resources/CGSession-switchToUserID 502“
是我的问题,另一行代码通过ssh工作

所以,我不能在远程Mac上通过ssh使用CGSession