If I run the following command in Apple Script Editor directly,

display notification "Hello, world"

I can see a notification as expected

However if I tried to invoke it via command line:

 osascript  -e 'display notification "Hello, world"'

It turns out I am running it in a tmux session. If I just ran the command in my default shell, it works as expected.

How can I get it to work with tmux?

  • The osascript line works fine for me… – Asmus Feb 28 '15 at 14:14
  • Are you doing it over ssh? What version of OS X? – 0942v8653 Feb 28 '15 at 17:25
  • I ran it in a tmux session. Apparently it did not work if I call it in a tmux session, but works fine in my default shell. Strange – Anthony Kong Feb 28 '15 at 20:30
  • This might be caused by the same issue complicating tmux access to the OS X pasteboard. See here for details, and check if installing reattach-to-user-namespace (brew install reattach-to-user-namespace if you are running Homebrew) helps. – kopischke Mar 2 '15 at 16:54

As @kopischke said, install or upgrade reattach-to-user-namespace may solve this problem.

If your reattach-to-user-namespace is old, notification works well after brew upgrade reattach-to-user-namespace.

  • And add the line to ~/.tmux.conf set-option -g default-command "reattach-to-user-namespace -l zsh" – mac May 28 '17 at 19:30

Building on @snomof's answer, you'll want to install reattach-to-user-namespace through Homebrew or MacPorts and wrap the call to osascript:

reattach-to-user-namespace osascript  -e 'display notification "Hello, world"'
  • And add the line to ~/.tmux.conf set-option -g default-command "reattach-to-user-namespace -l zsh" – mac May 28 '17 at 19:30

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.