Comments (8)
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.
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.
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.
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.
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
fi
from terminal-notifier.
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.
Thanks for the reports and sorry for taking so long, I hope this adequately fixes the problem.
from terminal-notifier.
The problem still exists. terminal-notifier
does not work if running using launchctl load
.
from terminal-notifier.
Related Issues (20)
- `terminal-notifier` errors on macOS Big Sur HOT 11
- How button text(actions) supports Chinese HOT 1
- [INFO] macOS Big Sur 11.0 beta reports & issues HOT 13
- Snooze
- Stacked notifications? HOT 3
- -open: Click terminal-notification then brings another notification HOT 12
- -activate not work with icon.
- No Notification in macOS12.1 HOT 6
- dropping msg 1 app not found HOT 3
- Mention in README that sticky notifications can be controlled by System Prefs
- Fail to pop up when trigger in python subprogess with crontab -e HOT 1
- how can I customize alert sounds HOT 1
- Can't play system alert sounds on Ventura 13.1
- use -sender will stuck on ventura HOT 1
- notifications are muted and i can't unmute HOT 1
- cannot use with teams deeplinks
- The timeout option is no longer available?
- No notifications during screen recording HOT 2
- -open does not work in macOS Sonoma HOT 2
- Notifications not appearing in macOS Sonoma 14.2.1 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from terminal-notifier.