sheagcraig / yo

Send Notification Center messages from the command line
Apache License 2.0
383 stars 44 forks source link

NSNotificationCenter Connection invalid #37

Closed stickman112 closed 5 years ago

stickman112 commented 5 years ago

Trying to identify what could potentially be causing the below message when using SSH to run a notification. The notifier works fine when its run locally, VNC session, and Self-Service(JAMF MDM Store).

Have tried everything I can think of, but not sure whats going on. Is it possible this is permissions based? Tried changing it to a few different things but the result is the same. Any help appreciated!

bash-3.2# /Applications/Utilities/yo.app/Contents/MacOS/yo -t "MyCompany" -s "Header" -n "Message ..."
2018-12-05 12:53:06.442 yo[65652:994752] NSNotificationCenter connection invalid
2018-12-05 12:53:06.443 yo[65652:994751] Posting notification.
com.mycompany.yo
2018-12-05 12:53:06.444 yo[65652:994752] Connection to notification center invalid. ServerConnectionFailure: 1 invalidated: 0
sphen13 commented 5 years ago

Looks like you are calling yo as root. This should be called directly as the end user who is logged into the GUI or via yo_scheduler as root.

stickman112 commented 5 years ago

Ahh, thanks @sphen13 ... that did it. Appreciate your help!

GenoMyb commented 4 years ago

@stickman112 please share your code

I did the following and still failing

sudo -u $currentUser /Applications/Yo.app/.....

sphen13 commented 4 years ago

here is a sample that i have

consoleUser=$(/usr/bin/python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "\n");')
consoleUserUID=$(/usr/bin/id -u "${consoleUser}")
launchctl asuser "$consoleUserUID" "$notificationAgent" -z Tink -t "$notificationTitle" -n "Updates have been due for $oldestUpdateDays days, Please Update Now" -b "Update Now" -o "Later" -a munki://updates > /dev/null 2>&1
GenoMyb commented 4 years ago

Failed to get user context: 1: Operation not permitte

when using currentUser=$(stat -f%Su /dev/console) launchctl asuser "$currentUser"

sphen13 commented 4 years ago

please see code above - the launchctl command require a uid not a name - you are supplying a name. This is not a yo issue.

GenoMyb commented 4 years ago

Ok thanks will fix that thanks