Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TN not working from launchd #259

Open
2 tasks
Vartkat opened this issue Aug 31, 2018 · 6 comments
Open
2 tasks

TN not working from launchd #259

Vartkat opened this issue Aug 31, 2018 · 6 comments

Comments

@Vartkat
Copy link

Vartkat commented Aug 31, 2018

Please check everything that applies to your issue:

  • [X ] I looked in closed issues and it has not already been answered
  • My issue appeared with a terminal-notifier update
  • I'm using a tool that uses terminal-notifier (guard-notifier, node-notifier...)

To help us debug your issue please include:

  • the macOS version you use
    10.10
  • terminal-notifier version
    2.0
  • how did you install terminal-notifier (binary download, homebrew, ruby gem...)?
    Homebrew
  • step-by-step reproduction instructions
    Make a simple bash script which fires terminal-notifier (in /usr/local/sbin), make a launchd plist file calling this script with
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>EnvironmentVariables</key>
    <dict>
           <key>PATH</key>
           <string>/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin</string>
    </dict>
	<key>AbandonProcessGroup</key>
	<true/>
	<key>GroupName</key>
	<string>admin</string>
	<key>InitGroups</key>
	<true/>
	<key>Label</key>
	<string>YOUR_PLIST_NAME</string>
	<key>Program</key>
	<string>YOUR_SCRIPT_PATH</string>
	<key>RunAtLoad</key>
	<true/>
	<key>StandardErrorPath</key>
	<string>/tmp/YOUR_PLIST_NAME.stderr</string>
	<key>StandardOutPath</key>
	<string>/tmp/YOUR_PLIST_NAMEn.stdout</string>
	<key>StartInterval</key>
	<integer>3600</integer>
	<key>UserName</key>
	<string>YOUR_USERNAME</string>
	<key>WorkingDirectory</key>
	<string>/Users/YOUR_USERNAME</string>
</dict>
</plist>

in /Library/LaunchDaemons
(note - StartInterval with a value of 3600 fires the script every hour)

To run the script load the plist
$ sudo launchctl load PLIST_FILE
To stop it unload the plist file.

Using terminal-notifier the whole script gets stuck as if it was asleep (no error).
I had to kill terminal-notifier so that the bash script resume (terminal-notifier was a sub-process of the script).

I also tried replacing TN with osascript display notification but that doesn't show anything on the user screen.

I thought it was because launchd launched processes are running as root but with UserName it should run as the named user.

Notting suspicious show up in the Console.

@Vartkat
Copy link
Author

Vartkat commented Sep 4, 2018

I had installed terminal-notifier using brew, according to https://superuser.com/questions/734563/terminal-notifier-fails-silently-when-called-from-launchd I have to run terminal-notifier from the app bundle, so I did an alias of /usr/local/Cellar/terminal-notifier/2.0.0/terminal-notifier.app in in /Applications folder, it doesn't work better, I tried an ln -s but that neither does it run (it says too manu symlinks).
If I do a
ps -axw | grep term
I see that terminal-notifier is stuck, I have to kill this process so that the script resumes.

@julienXX
Copy link
Owner

julienXX commented Sep 4, 2018

Hi @Vartkat maybe the solution described in #148 can help.

@Vartkat
Copy link
Author

Vartkat commented Sep 4, 2018

The solution in #148 by @applebit924 seems a bit cryptic to me. I understand he's notifications are not fired by his main script but by a script fired by a watchdog. The watchdog runs from /Library/LaunchAgents and not from /Library/LaunchDaemons, but for the rest I don't see terminal-notifier in there unless he renamed it "Software Update Notifications" and I don't understand why he's building a notification script each time he needs to show a notification. Seems very complicated.

@gregneagle
Copy link

launchdaemons run as root. I would not expect root to be able to post an NSUserNotification.

@Grayon
Copy link

Grayon commented Oct 28, 2019

This works for me. Use 'open' command.
open terminal-notifier.app --args -message "123"

@Droid43
Copy link

Droid43 commented Nov 20, 2019

@Vartkat A GUI can't be launched by a daemon in macOS.
'open' command can work well.
open -a terminal-notifier --args -title "test"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants