{"id":36,"date":"2007-11-23T15:20:36","date_gmt":"2007-11-23T22:20:36","guid":{"rendered":"http:\/\/www.kernelcrash.com\/blog\/2007\/11\/23\/jabber-messages-in-your-dwm-status-bar\/"},"modified":"2008-01-05T12:18:49","modified_gmt":"2008-01-05T19:18:49","slug":"jabber-messages-in-your-dwm-status-bar","status":"publish","type":"post","link":"https:\/\/www.kernelcrash.com\/blog\/jabber-messages-in-your-dwm-status-bar\/2007\/11\/23\/","title":{"rendered":"Jabber messages in your dwm status bar"},"content":{"rendered":"<p>One of the features of dwm is that whatever you pipe into stdin ends up in the status bar at the top of the screen.   I thought this would be a great way of getting the last message from a jabber chat onto the screen.<\/p>\n<p>There aren&#8217;t really a lot of examples of how this works. I think there is one in the dwm README file that shows how to get a clock into the status bar. You put this into your ~\/.xinitrc:<\/p>\n<pre>\r\nwhile :\r\ndo\r\n   date\r\n   sleep 1\r\ndone | \/usr\/local\/bin\/dwm<\/pre>\n<p>I thought I&#8217;d just redirect stdin for dwm from a fifo file and then I can pump data into the fifo whenever I like. ie. Put this in your .xinitrc<\/p>\n<pre>\r\n[ -f \/tmp\/myfifo ] &amp;&amp; rm -f \/tmp\/myfifo\r\nmkfifo \/tmp\/myfifo\r\n\/usr\/local\/bin\/dwm &lt;\/tmp\/myfifo<\/pre>\n<p>I found that didn&#8217;t work as I expected and dwm tended to hang on startup (maybe it was waiting for something in the fifo??<\/p>\n<p>I use mcabber as a jabber chat client, so here is what I did to get the status bar to update with the last chat message<\/p>\n<p>1. In .xinitrc I have:<\/p>\n<pre>\r\ntouch ~\/.mcabber\/log\r\ntail -f ~\/.mcabber\/log | while read x\r\ndo\r\n   cat \"$x\"\r\n   # remove the message file since nothing else will\r\n   rm -f \"$x\"\r\ndone | \/usr\/local\/bin\/dwm<\/pre>\n<p>2. In ~\/.mcabberrc I turn on event logging and have an event script:<\/p>\n<pre>\r\nset events_command = ~\/mcabber-eventcmd.sh\r\nset event_log_files = 1\r\nset event_log_dir = ~\/.mcabber\/event_files<\/pre>\n<p>3. In my ~\/mcabber-eventcmd.sh script I have:<\/p>\n<pre>\r\n#!\/bin\/sh\r\nif [ \"$1\" = MSG ];then\r\n   aplay ~\/chat2.wav\r\nfi\r\nif [ \"$1\" = MSG ];then\r\n   echo \"$4\" &gt;&gt;~\/.mcabber\/log\r\nfi<\/pre>\n<p>The aplay command is purely to play a sound when I get a new message, but the 2nd if statement appends the event file for the message to a log file (this is the log file referenced in the .xinitrc).<\/p>\n<p>So what happens is that you get a message in or out in mcabber, it runs the mcabber-eventcmd.sh script. That script appends details of a message file to a log file. Meanwhile the while loop in the .xinitrc is watching that log file. Everytime there&#8217;s a new line in the log file, the content of the file is piped into the stdin of dwm (via the &#8216;cat&#8217;)  and the message appears on screen.<\/p>\n<p>The scripts above are simplistic .. and don&#8217;t handle very long messages or multiline messages very well. And you&#8217;ll notice that the status bar takes about 1 second to change (this is probably to do with the tail -f)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the features of dwm is that whatever you pipe into stdin ends up in the status bar at the top of the screen. I thought this would be a great way of getting the last message from a jabber chat onto the screen. There aren&#8217;t really a lot of examples of how this [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-36","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.kernelcrash.com\/blog\/wp-json\/wp\/v2\/posts\/36","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kernelcrash.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kernelcrash.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kernelcrash.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kernelcrash.com\/blog\/wp-json\/wp\/v2\/comments?post=36"}],"version-history":[{"count":0,"href":"https:\/\/www.kernelcrash.com\/blog\/wp-json\/wp\/v2\/posts\/36\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.kernelcrash.com\/blog\/wp-json\/wp\/v2\/media?parent=36"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kernelcrash.com\/blog\/wp-json\/wp\/v2\/categories?post=36"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kernelcrash.com\/blog\/wp-json\/wp\/v2\/tags?post=36"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}