 It seems like every couple of months or so I get the sudden urge to do some bash scripting and today was one of those days I was here at the office today. Initially, I wasn't planning on making a video I was here doing some administrative work and I was wanting to listen to some online radio And I thought wouldn't it be great if I had a D menu script that allowed me to choose between various online radio Stations to listen to and that's what I did I spent about two hours playing with some bash script and creating this D menu script that allows me to listen to various radio stations of my choosing and what I did is I went to this particular website Zeno.fm And if you click the discovery link here, it's a search link and then you get a search bar You can search for various genres names of radio stations that sort of thing Now I'm not going to be able to play any music on today's video because all of these radio stations Are going to play copyrighted music and that would get my video flagged So I've got the sound muted nobody's going to hear anything playing But say I wanted to add Radio Jamaica 94 fm to my eventual script What I did is I went to this page once you get to the radio stations page here in Zeno.fm Copy the URL just go and get the web address and copy that and then use that to create a list Of various radio stations that you'll eventually want to add to your D menu script And then let me go ahead and launch emacs and I'll show you the script that I Created today. So let me go to the tub and zoom way in so you guys can see a little bit of this Let me toggle on truncated lines here So we don't have these extra long lines running off the screen here. Yeah, that looks a lot better So I'm going to go over exactly what this script is now this script looks a little lengthy It actually looks longer than it is because a lot of this stuff I mean the first 12 lines here are comments. This is going to be part of my DM scripts Repository which DM scripts is an installable program. It's available in the AUR It's also available as part of DTOS. Although I haven't made DM radio a part of that just yet I'll try to do that either later this evening or hopefully by tomorrow It will be a part of DTOS But if you wanted to create such a script yourself I mean you all you really need is the shebang at the top Obviously, you need the crunch bang slash user slash bin slash env space bash Because it is a bash script and the rest of the comments are just Here to tell you about dependencies. This script is going to depend on d-menu mpv and dunst And the first line of real code set dash euo pipe fill I do that in all my DM scripts because what this does is this particular line here It calls us the script to fill if certain things happen And that's a good thing. Otherwise we could get hidden bugs that are hard to discover You see I even left a comment explaining all of that This here is code that is specific for anything part of the DM scripts So what this does it goes and looks for a helper file that's available as part of the DM scripts packaging And it's not specific to what we're doing here and we're going to source a config file again That's not necessarily anything that we need to to focus on here is actually the real Part of the script here So we have menu and then the opening and closing parentheses and then an opening brace and then everything in between the brace Is part of a function. This is a bash function That is anytime you get a name followed by those opening and closing parentheses and then the braces, right? So this function I called menu I could have named it anything But all it does is it runs print f and it just prints lines and it prints a new line after every entry That's up the last line. We don't need a new line after the very last line So we have that menu function and then I created this function here start underscore radio And then we run dunstify, which is part of the dunst notification system And it's just going to have a notification box when I execute or when I start playing a radio station It's going to say starting dm dash radio playing station and then it's actually going to give me the name of the station I also created a end underscore radio function where dunst lets us know that we actually quit out of dm dash radio And then we have choice equals and choice equals Menu remember the menu function that just prints, you know, all of our radio stations It's just numbers and titles really Well, it takes all of that information and it pipes it into d menu. Now. This is a variable That's part of the dm scripts package So in your own scripts, you would actually have to write the word d menu with various flags for d menu But I've substituted that for that particular variable And then we have a d menu prompt which in my case is going to say choose radio station colon And then we're going to pipe that into the cut command I did a video about the cut command and what this is going to do dash d Period it's going to use the period as a delimitator and then it's going to do dash f one We want field one. So what it's going to do It's going to find a period in each of these lines That is the deliminator the separator and then it's going to take the first field based on those periods Which is in this case one all it's going to do is cut out one Then it's going to cut out two then it's going to cut out three now on the very first option quit It's going to cut out the whole word quit because there's no period And what this allows me to do by doing that cut command is later I'm going to have a case statement where I have each option listed out one through 16 plus quit Well, I don't want the option for number one Let me find number one here in the case statement I don't want that to actually have to read out one period space 50 space rewind right That's a very lengthy name for that right there. I only want to have to use one right That's why we in this year we ran that that cut command right now. Let's talk about this case statement here Let me zoom back out here So you guys can see this very lengthy case statement So what do each of the choices do well if I launch the script here I've got this as set as a hot key if I do super p followed by r That is the dm radio script and you can see quit and then went through 16 I added 16 radio stations at least initially here now if I chose quit what that does is it runs the end radio Function that we defined up here, which is done specify and then it gives this message If you guys want to see that I could do super p followed by r and then just choose quit and you can see We get a notification. We just stopped dm radio Now if we had dm radio already running, it would also kill dm radio already running by killing this particular process here So that is what quit does now everything else 1 through 16 here in the case statement What this does is if dm radio is already running it kills it And if it's not running it just echoes in the terminal if you were running this from the terminal mpv not running Then after that we run the start radio function, which is the dunce command again But this time it's going to let us know that we're now playing this particular radio station So that is 50s rewind. Let me show you that so super p r and then 50s rewind you say it says playing station 50s rewind. Let me turn the volume down And now let me quit stopping dm radio and that really is the entire script I mean, this is just the rest of the case statements I did add a extra Option here in the case statement this asterisk means if anything else happens If I choose anything other than quit or 1 through 16 because the strange things can happen with scripts sometimes So you always want to have this asterisk in a case statement just in case anything weird goes on Then I want you to just echo program terminated and then exit. So that's really the script again It's very simple. I just go in here and choose anything to play and if I start playing something You know this particular station, we're not going to listen to it, but it's playing in the background I promise you music is playing and while that's playing if I wanted to run the script again And then choose a different radio station to play It will kill the running process and then start playing the new station we selected So really there's nothing to this script. Let me zoom back out Well, I zoomed way back out Let me zoom back out so you guys can get an idea for how big this script is Because other than the comments and then this stuff here that is really specific to anything packaged for dm scripts You guys won't need to know that really all I did was created this menu function With our various options and the start radio and the end radio functions for our notifications And then choice equals the menu function piped into dmenu again Then we cut out the very first field based on the periods in these names here in the menu function And then we have our case statements and when we choose the quit function It just gives us the end radio notification and kills any running processes If we choose an actual radio station to play it kills any running functions And then it gives us a start radio notifications And then it starts the new function or the new process on the radio station that we chose. So really this I could have probably written this In 30 minutes It took me a couple of hours mainly for searching radio stations because I actually did have to go and You know look through all of these radio stations and searching for various ones And some of the ones I searched for on this site When I went to play them nothing happened I don't know if the stations are down certain hours of the day or maybe the station is now dead Whoever was maintaining it just got tired. So I did have to go and I probably looked through about 50 radio stations before narrowing it down To the 16 that I eventually settled on now for those of you that want this particular script You can find it on my git lab look for my git lab in the show description And you're going to want to go to my dmscripts repository for those of you on an arch based Linux distribution You can install the entire dmscripts package with uh a ur helper like yay or paru look for dmscripts dash Git that is the name of the package those of you that are running dtos You will have dmscripts available through just pacman and not dmscripts dash get just dmscripts I haven't added the radio script to dtos just yet again I'll try to get to that this evening or maybe tomorrow now before I go I need to think a few special people I need to thank the producers of this show And of course, I'm talking about devon gave james matt michael michael paul scott west alan armor dragon chuck commander angry Dio kai dylan george lead linux ninja maxim mike irion alexander peace arch and for door polytech red prophet Stephen willey these guys they're my highest-tiered patrons without these guys This episode wouldn't be possible this channel wouldn't be possible Shows also brought to you by each and every one of these fine ladies and gentlemen All of these names you're seeing on the screen these guys. They're great people without these guys Again, I couldn't do what I do. I don't have any corporate sponsors It's just me and you guys the community if you like my work Please consider subscribing to distro tube over on patreon. All right guys peace Is there anything demon you can't do