osascript set volume 无法通过 ssh 工作

osascript set volume isn't working via ssh

这是我的情况。

用户 A 当前登录到 计算机 A

用户 B 通过 ssh 登录到 计算机 A

用户 B 通过终端 a osascript (osascript -e 'set volume 0')

运行

这是我的错误日志:

Oct 20 13:25:17  osascript[29389] <Error>: Set a breakpoint at CGSLogError to catch errors as they are logged.
Oct 20 13:25:17  osascript[29389] <Error>: This user is not allowed access to the window system right now.
Oct 20 13:25:17  osascript[29389] <Warning>: CGSConnectionByID: 0 is not a valid connection ID.
Oct 20 13:25:17  osascript[29389] <Warning>: CGSConnectionByID: 0 is not a valid connection ID.
Oct 20 13:25:17  osascript[29389] <Warning>: CGSConnectionByID: 0 is not a valid connection ID.
2015-10-20 13:25:17.196 osascript[29389:1503684] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data
2015-10-20 13:25:17.197 osascript[29389:1503684] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data
2015-10-20 13:25:17.197 osascript[29389:1503684] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data
2015-10-20 13:25:17.197 osascript[29389:1503684] CFPasteboardRef CFPasteboardCreate(CFAllocatorRef, CFStringRef) : failed to create global data
Oct 20 13:25:17  osascript[29389] <Warning>: CGSConnectionByID: 0 is not a valid connection ID.
_RegisterApplication(), FAILED TO establish the default connection to the WindowServer, _CGSDefaultConnection() is NULL.
Oct 20 13:25:17  osascript[29389] <Warning>: CGSConnectionByID: 0 is not a valid connection ID.
Oct 20 13:25:17  osascript[29389] <Warning>: CGSConnectionByID: 0 is not a valid connection ID.
Oct 20 13:25:17  osascript[29389] <Warning>: CGSConnectionByID: 0 is not a valid connection ID.

旁注 用户 B 设置为 admin

曾几何时,我记得以前执行过这种情况,没有任何错误。不确定这是否是具有特权的 ARD 设置

我找到了一个似乎有效的替代方法...

如果我加上

sudo -u usernameosascript -e 命令之前,然后就可以了。

例子

sudo -u username osascript -e 'set volume 0' 

从阅读内容来看,苹果似乎不允许用户在另一个用户登录时通过 ssh 会话打开 应用程序。必须以当前用户身份登录才能运行 osascripts,否则,添加如下命令 sudo -u username