This is my modification of "Irssi in Mac OS X Notification Center" for weechat
This guide will explain how you can make irc messages in a screen on a remote server appear in your Mac OS X Notification Center with the help of terminal-notifier.
- Login to my Mac
mac$ ssh cloin@weechat-server.example.com
This is a virtual instance of Fedora 20weechat-server$ tmux attach -dt weechat
- Communicate. All of my highlights are displayed in my local Mac's notification center
- Requirements
- Part 1: Writing messages to file on a remote server
- Part 2: Installing terminal-notifier on your Mac
- Part 3: Read messages from server and send notifications
- Troubleshooting
- Mac OS X 10.8 or greater
- Python 2.7+ on the weechat server (dependency on
from collections import Counter
added in python 2.7) - Remote server running a screen or tmux session with weechat
- You use an ssh key to connect to the remote server (For Part 4 atleast)
- Basic knowledge on the above terms and programs including Terminal
We first need a script running on the remote server running weechat to log all highlights to a file. I'm using hl2file.py here but there's definitely room to improve this script. For instance, this script doesn't log private message which I obviously want to be alerted to.
Install the above script in weechat using the script command and have it autoload
After installed and loaded, weechat should log all highlights to ~/.weechat/highlights.txt
terminal-notifier is a very useful tool that makes it easy to trigger OS X Notifications from Terminal and scripts.
The official readme from the developer should be good enough to show you how to install and use it.
Easiest way to do install is with brew with the command brew install terminal-notifier
I recommend the brew approach because its a package manager which allows for easier updates and can be used to install a ton of other packages. Cakebrew is a gui frontend for brew and it's quite nice.
If you don't want to install brew, you can:
The next parts assume however that you have installed the ruby-version as detailed below. Ruby on your Mac will be required
- Type
gem install terminal-notifier
in Terminal
Once the ruby-version is installed you can test it by typing the following in Terminal.
terminal-notifier -title 'Title' -message 'This is a simple test message.' -activate com.apple.Terminal
This should cause a notification message to appear on your screen and you will see the confirmation message * Notification delivered.
in your Terminal window. If you click on the notification box you will activate Terminal.
Now you need to create a script on your Mac that will read from the file on the server in "real time" and then send the messages to the Mac OS X Notification Center with terminal-notifier.
Below we have provided you with a basic function you can use and experiment with. This script displays the messages but will also look for links. If it finds a link it uses the -open flag in terminal-notifier to make it so the url opens in your browser if you click on the notification message. When there is no link it will activate the Terminal-window instead.
weechat_notifier() {
ssh user@weechat-server.example.com 'echo -n "" > ~/.weechat/highlights.txt; tail -f ~/.weechat/highlights.txt' | \
while read heading message; do
url=`echo \"$message\" | grep -Eo 'https?://[^ >]+' | head -1`;
if [ ! "$url" ]; then
terminal-notifier -title "\"$heading\"" -message "\"$message\"" -activate com.apple.Terminal;
else
terminal-notifier -title "\"$heading\"" -message "\"$message\"" -open "\"$url\"";
fi;
done
}
weechat_notifier
The above script will create the weechat_notifier() function and then call the function when you login to your Mac. (I haven't tested what happens when you login and don't have access to ssh to that server.)
Please note that you will need to change ssh user@weechat-server.example.com
in the code above to your correct information.
- Open or create the file
~/.bash_profile
- Copy and paste the code above into
~/.bash_profile
- Fix the ssh-details in the script and save
- Reload
.bash_profile
by typing. ~/.bash_profile
in Terminal
I didn't do much, it just worked for me. One thing I did have issues with was the plist approach used here in the original irssi setup. I just don't understand launchctl enough to understand the value instead of the .bash_profile contained approach here and I hit too many errors and didn't want to spend the time learning it.
The original irssi setup has more information so check out the last steps of the original and many thanks to prebenlm
Is it expected that if you re-source ~/.bash_profile with this script added when you're already logged in, that it will keep running in the foreground? I.e. control won't return to the original shell?