Giter VIP home page Giter VIP logo

Comments (8)

kmarty avatar kmarty commented on May 16, 2024 1

Nevertheless you brought me to this thought:
ps aux | grep NotificationCenter | grep -v grep | cut -d' ' -f1 |
while read JUZR; do
su - "$JUZR" -c "terminal-notifier -message "$1""
done

Because I need to tell it to anyone who is logged (a broadcast message :-)). And this works.

EDIT: Wow, I should refresh page before I'm trying to send a new post :-). You wrote the same.
BTW. 'sudo -u user ...' doesn't work. It freezes.

from terminal-notifier.

kmarty avatar kmarty commented on May 16, 2024

Same problem if terminal-notifier is called by bash script which is called by launchd (using /Library/LaunchDaemons/...plist). It simply hangs.

from terminal-notifier.

casaschi avatar casaschi commented on May 16, 2024

I found a workaround that seems to work also when called by launchd, it would be nice to have a confirmation from other users. This is for calling terminal-notifier from a bash script, checking first if the user has a running instance of NotificationCenter, otherwise it's pointless to send the notification.

if [ -n "$(pgrep -u $(whoami) NotificationCenter)" ]; then
terminal-notifier -message "$*"
fi

While a fix in terminal-notifier would be welcome, this seems to avoid the hanging issue. Does it work for you also?

from terminal-notifier.

kmarty avatar kmarty commented on May 16, 2024

My bash script which is called by launchd is started as user 'root' and this user doesn't have running NotificationCenter ever.
The easiest thing ("workaround") is to remove notification at all because condition is false forever. Unfortunatelly this is not solution, becasue the main goal is to notify user (terminal-notifier was try to replace growl which is working in this case).

from terminal-notifier.

casaschi avatar casaschi commented on May 16, 2024

Your issue is that terminal-notifier sends the message to the NotificationCenter of the current user, and root is not logged in with the graphical UI ever. I dont have the issue because I use a user specific launchd.

You could play with sudo so that the root user impersonates your user when sending the notification, that might work. Still check for the given user having a NotificationCenter process, otherwise the script will hang.
Something like this should send a notification to the given user if logged in, otherwise skip the notification. I typed this without testing it, so you might have to doublecheck/debug, but you get the idea.

targetUser=kmarty
if [ -n "$(pgrep -u $targetUser NotificationCenter)" ]; then
sudo -u $targetUser terminal-notifier -message "$*"
fi

from terminal-notifier.

src73 avatar src73 commented on May 16, 2024

I thought that I'd write a conclusion to this thread for n00bs like me...

My shell script was working perfectly when I executed it as a user, but did not work when I ran it as root's launchd. My code was hanging (which for me meant that nothing was appearing in the logs because I had placed the terminal notification first). I fixed it by replacing terminal-notifier -message 'hi', with...

ps aux | grep NotificationCenter | grep -v grep | cut -d' ' -f1 | \
while read JUZR; do
    su - "$JUZR" -c "/path/to/terminal-notifier -message \"$your_message\" -title \"$your_title\""
done

...which will display the notification to all users who are logged in and have a notification center running, including you.

EDIT: this only works if the launchd is being run as root. If it is being run as user, it just needs

/path/to/terminal-notifier -message "$your_message" -title '$your_title'

from terminal-notifier.

alloy avatar alloy commented on May 16, 2024

Thanks for the reports and sorry for taking so long, I hope this adequately fixes the problem.

from terminal-notifier.

ddmytrenko avatar ddmytrenko commented on May 16, 2024

The problem still exists. terminal-notifier does not work if running using launchctl load.

from terminal-notifier.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.