问题
here is my situation.
User A is currently logged on Computer A.
User B logs into Computer A via ssh.
User B runs via terminal a osascript (osascript -e 'set volume 0'
)
here is my error log:
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.
Side notes User B is set as admin
Once upon a time, I recall executing this situation before without any errors. Not sure if this is a ARD setting with privileges?
回答1:
I've found an alternative which seems to work...
If I add
sudo -u username
before the osascript -e
command, then it works.
example
sudo -u username osascript -e 'set volume 0'
from what a read, seems that apple does not allow users to open applications via ssh session while another user is logged in. Must be logged in as the current user to run osascripts
, otherwise, add the following command sudo -u username
来源:https://stackoverflow.com/questions/33247260/osascript-set-volume-isnt-working-via-ssh