 One of my favorite things to do on this channel is to come up with a problem that exists on Linux and then solve that problem through the use of some basic bash scripting or using some of the basic command line Utilities the GNU core utilities things like that and today I came up with this problem that exists on Linux that's very easy to solve and I'm really not going to get into a lot of scripting or programming or any nerdy stuff I'm going to show you how a typical Linux user solves these problems and how they typically solve these problems is you do a quick Google search or whatever you you typically you'll find solutions on forms such as stack overflow And then you just do a copy and paste somebody's probably already written the script for you And then you just implement that into your workflow. So the problem I was wanting to solve today was desktop notifications. You get your little desktop notifications on Linux When you get a new email, you'll get a little box saying you've got a new email or when somebody Messages you on social media like mastodon or something you'll get the little pop-up box And I always assumed that these notifications were logged somewhere on Linux like there was some file somewhere Where all of your notifications were written to that you could go back and later view this stuff But that's actually not the case some desktop environment some of the bigger desktop environments You know, they'll have little widgets where when you click on your notifications They'll give you a list of your past and full of notifications or whatever I know that exists in GNOME, KDE Plasma, Budgie has little side panel that pops out with your notifications But you can't go very far back in your history and these things are really not permanently saved anywhere It's not like you can go back and read notifications from like last week last month last year Well, I want these things permanently saved to a log file So let me switch over to my desktop and show you a little bit of what I want to do here I'm an X-mone ad today. So I'm in a tiling window manager X-mone ad The panel at the top here is the X-mobar panel and that's important to know because first of all I'm going to open a terminal and I'm going to go ahead and zoom in a little bit And I'm going to send myself a message instead of waiting for like an email or something to come up You could be waiting for minutes or even hours for your next desktop notification I'm going to do notify-send. Notify send takes two arguments Typically the first argument is often the program sending you the message or the online service sending you the message Or whatever it happens to be so I could do something like Firefox And maybe the message that Firefox is sending me is some message Okay, and if I click on that you can see I get the notification my little desktop notification from Firefox Sending me some message now. Let me click on the desktop notification. So it goes away Now imagine I didn't really read that message. Maybe it was important, you know, for whatever reason I just wasn't thinking I clicked on it, you know out of habit and I really wanted to read that message I can't go back and read it now. Well an X-mobar I've now added this widget here with the little Twitter icon, you know because so many of your desktop notifications or social media Messages anyway, I added the little Twitter icon view notifications. And if I click on this widget Look what happens it opens a text file here, which I called notify log And I put that in my home directory in a hidden directory called log It should exist on your system anyway And you can see I have all of my past notifications including some message from Firefox here Now let me actually Clean up this log just so it's obvious. So let me just make it an empty file again And let's do a notify send and this time maybe the notification is coming from something like a mastodon You have a New message and if I go back to the file you can see mastodon I have a new message and you can say I've got the the notification here as well So that is really neat as long as I never delete the log You know, I I could keep this thing running for weeks months or even years I could go back and read past notifications Now, how did I get this to work? Well, it actually was not that complicated if I switch over to my web browser here All I did was do a google search on linux desktop notifications logging You know saving or logging them or whatever and I quickly realized that this is a common problem on linux is that Your notifications are not logged somewhere. They're not saved permanently somewhere And one of the top google searches I did was this thread on askaboon2 Which is part of stack exchange, right? And then this guy had this little script here very interesting little bash script There's not much to it. There is a program here debus monitor You can see debus monitor. It's going to monitor for notifications on your system Then you pipe it into grip several times you're gripping various things out of that And then through the magic of xorgs You're taking the result of all of that gripping and you're passing that as an argument into echo And you're echoing into file And of course file could be the name of any file you choose and later in the post He actually cleans it up a bit where he has a version where he adds the date as well and you could see that Exactly that's the one I'm actually using here It adds the date for a line and then the first argument to notify send and then date again And then the second argument as well and this is typically how Even somebody like me. I know a little programming and scripting, you know a lot of times I just Take stuff from the internet. Just go to stack exchange, right? Anytime you find a problem I mean you could sit here and write your own script But a lot of times especially for those of you that fear scripting somebody's probably Put in the work for you. Now, let me switch over to this emacs buffer. This is deer ed inside emacs Which is essentially a file manager. This is my home directory if I go into dot local Slash bin, you know, these are scripts on the system, right? And I now have this script that I titled notify dash log Let me hit enter zoom in and that's essentially that script that I just ripped from stack exchange, right? Let me turn off the truncated lines Let me zoom out a little bit here and you can see there's not much to it log file It's just a variable name. I could have named it anything equals a dollar sign one So that's I'm going to give this script an input the input should be the name of a file And then it's just running this debus monitor interface free desktop notifications command, which is piped into grip several times where it's Doing some red jacks and some pattern matching and it's taking the appropriate lines And then with xorgs is taking those as an argument for the print f command So print f equals and then it's going to print out the date And then it's going to print out a new line and then you got the opening and closing braces That is what xorgs is going to pass into the printf command So that's going to be the two arguments from the notify send command And then you've got the two right pointing chevrons the two greater than signs meaning we're going to append that information To dollar sign log file. So whatever log file, whatever the name of that file I'm using it's always going to append that file with each new notification And then all I need to do is run this script and make sure this script is running in the background It's a background process. So typically I think the easiest way to make this magic happen Is in your window manager. Let me zoom in. This is xmonad. I've got my auto start start up hook here And you can see now I have spawn once notified dash log because that's the name of the script And I don't have to do the full path because dot local slash bin is where that script is currently living And that is part of my shells path. So I can just do notify dash log and then I have to give it an argument And the argument should be where the location of the log file that you want to write to So every time I log into xmonad or restart xmonad, it's going to start this notification log script That is essentially running in the background and every time I get a desktop notification It's going to write to that log file. So, you know, I can quickly pull it up any time I want to read those notifications And of course, you know, I didn't just have to edit my xmonad config. I also had to edit the xmobar config as well. So let me open my doom one xmobar rc color scheme here Once again, let me turn off truncated lines here I'm going to zoom in just a little bit. Let me make this full screen. So it'll be a little easier So this is my xmobar rc. All I did was I added two new widgets here So you can see run com. So that's run command any shell command and the command I'm going to run is the echo command I'm going to echo this font awesome icon and the font awesome icon is the little tweety bird, right? So and then I named this widget messages And I wanted to run every 3600 seconds, you know, it doesn't have to run very often because that icon of course It's never going to change and then the next line if we ignore the commented lines Is run command echo and we're just going to echo the words view notifications And then I named this widget notify dash log and then later in the template section of xmobar I actually have Messages wrapped in percent signs. So that's very important. You see the beginning and the trailing percent signs around messages That's letting me know but that is a widget that I've created and you know, that's the uh A tweety bird icon right the messages widget there and then the next widget is the Notify log widget, which is simply the words view notifications and I have that wrapped in this action Tag here action is a clickable event for xmobar when I click it. What is the action? I want the action to be I want you to open the alacrity terminal And then I want you to open neovium inside alacrity and I want you to read dot log slash notify dot log So it looks like it's a lot of complicated stuff But it really isn't and again if we wanted to see uh some of this in action just to verify that this is working Let's do another uh notify send and I'm just going to do It's from somebody named one and he's sending me this message Two I one two right here click on it and you can see that the log automatically changes There's one two and you know, that's just going to be my notification log It should exist forever and you know until maybe one day it gets to such a size Maybe I want to delete it and start afresh So there you have it a little bit of different kind of video because it's a real world problem But I really didn't do anything nerdy I actually showed you Kind of behind the curtain the secrets of the linux power user the desktop power user where we have a problem How do we solve it? Well, I did a google search and I found somebody that wrote a little code on stack exchange And I took that code now I had to actually do something with this code and the code by itself really didn't do anything I had to implement that code into what I'm already using as far as I had to implement it into x-mode add and x-mode bar I had to decide where I was going to write to a log file the location how I was going to auto start the The monitoring the debuts monitor as well So, you know, it took me 10 minutes 10 minutes to actually do that google search and then get all of this Up and running and the reason I show you guys these kinds of real world problems that you could solve Using scripting command line tools and things like that is because you need to know this and it's one of those things people fear this But it's the more you do this the more you practice problem solving and that's all this is I mean It doesn't necessarily have to be linux related or programming related and things like that This is just life the more you get used to I've got a problem Let me figure out how to solve it The better you get at solving problems the better you become at Solving problems not just in tech but also in life And one of the most important reasons why you want to improve at these kinds of problem solving skills Especially those of you that are passionate about linux and free and open source software is the better you become at this Then the better equipped you are to help others now before I go. I want to thank a few special people I want to thank the producers of the show brian gabe james matt maxima Mitchell paul west 1 you both homie alex armor dragon chuck commander angry dieokai george lee march from nadir yon alexander paul Peace watch on the door polytech realities for less red prophet roland steven tools deviler and willy these guys They're my highest tiered patrons over on patreon without these guys This episode would not have been possible The show is also brought to you by each and every one of these fine ladies and gentlemen as well All these names you're seeing on the screen right now. These are all my supporters over on patreon because I don't have any corporate sponsors I'm sponsored by you guys the community if you like my work And want to see more videos about linux and free and open source software subscribe to distro tube over on patreon peace And if you want my config files check my dot files repository over on my git lab