 In the last video, I showed you some of my scripts on multi-selecting files to process with a shell script. Today, we're going to be looking at a few of those scripts in detail and actually look at the code and weigh some of the pros and cons. So let's jump right in. So again, as I stated in the last video, my GitLab page, gitlab.com forward slash metalx1000, I have a project called bash multi-file select. With the scripts we're going to be looking at today, there are multiple. We're going to look at two or maybe three of the scripts today because it's pretty short, pretty straightforward. But real quick, we're going to look at the fzf option. So fzf, I'm going to run that. It's going to list out the files that are in this directory and I can, well, I can click with my mouse to choose one if I want it, but I can use tab to select the ones I want. And if I want it to filter, I can do HDR and just show the HDR ones, although I did select some that aren't being shown right now. It shows right here that we're looking at 21 of 39 and I have 10 selected when I hit enter. It's going to convert them to black and white, desaturate them. So let's look at this code real quick. So files fzf, again, the top part is the header copyright information. And down here, okay, Inder, Outdoor, the input directory, output directory. Again, as I mentioned in the last video, I purposely put spaces in these folder names. That's something you really should avoid, but a lot of people don't. And I wanted to take that into account with our code because if you don't and someone puts a space in a file name or folder that you're selecting, everything goes wrong. So I purposely did that, but we have an input directory, an output directory, and then we're going to create the output directory. We're using makedir, so make a directory. I'm using a dash p option because what that will do is if the file already, if the folder already exists, you won't get an error in this particular case. And also if you have multiple subdirectories that don't exist, it will create all of them instead of having to create one at a time. Now, fzf, if you just run fzf, it will list all files in the current directory you're running it in if you don't pass it anything. I wanted to pass it our directory and in this case, only jpeg images. So I'm saying find, we're looking at our input directory. I'm saying iname, asterisk.jpeg because some, like my Canon camera capitalizes jpeg. But there's also only looking for JPG if you wanted to look for PNGs or sometimes jpeg, you would have to update the find command. Now, we're piping that into fzf. We're using the dash m option, which allows us to multi-select, which is the whole point of this script. And then I'm getting a prompt, select photos to convert, okay? Now, once we select them all and we hit enter, it's going to dump the list that we've selected into this while loop. And for each file, so what are we doing here? It's saying, this is a shorthand for an if then statement. What it's saying is, check the file, okay? If the file does not exist, so if it's a blank file. So basically, if we didn't select anything with fcf, break. Just break out of the loop and continue the script, which is the end of the script. We have a little bit of output here, we're echoing out file and the file name, so we know where we are in the process. And then I'm just using image magic to convert it to grayscale. I just realized I have type grayscale in there twice, I only need that in there once. Okay, anyway, so let's again run that script cuz I don't think I've shown. If I was to not select any, so how do you not select any? It's like it looks like, cuz if I just hit one now, it's gonna select the one I'm on. So how do you not select any? Well, if I type in a bunch of gibberish and there's nothing in the list I hit enter, the script just exits. If I didn't have that, it would try to process nothing and you'd get a little error on the screen, not a big deal. So that's the overview of our FCF multi-file select. Works great, but again, some people aren't comfortable with the shell. Personally, I think it's a great option for most things. We can use Xenity. Xenity is already pre-installed on a lot of systems. If not, it's probably in your package manager. It allows you to do a bunch of different dialogues including a file select dialogue. So again, if we do this, we run it. We get the same list as we do in FCF and I can shift select. I can control select. I could probably use my arrows and I don't know if there's any way to the keyboard to select one and then go to another. If there is, let me know. I've never really thought about that before. Cuz we'd use the mouse, which is fine. Whatever, we hit okay. It's gonna convert those images. Let's look at that script. Oh, gotta put a space there. Okay, it's very similar to our last script. So here, we got our input directory, output directory, create that directory. They were running Xenity and we're gonna get all the files and we're gonna put them into a variable. Thank you, variable called files. As long as it's not blank, so basically if we hit cancel on the screen or we hit okay without selecting any, it's just gonna exit, okay? Now, what do we do next? Well, then we're just gonna echo out that list. Now, how does Xenity pass you the variables? So it's gonna pass each file name separated by a pipe symbol. So to loop through with the while loop, what I'm doing is I'm echoing out the entire list and then I'm gonna say with TR, replace all the pipe symbols with new line characters. That's the way I came up with it. There might be a better way, but that's the way I came up with it. And then loop through that, we're gonna echo out converting in the file name. And then we're gonna, again, use that same image magic command, which again has grayscale in there twice and we really don't need that. I need to go ahead and probably remove that. Let's go ahead and delete all our output files. I will run my files Xenity. I'm gonna select two files, click okay. Make sure they still convert to grayscale, yep. So that was a little typo on my part, but I will fix it and reupload it to get lab. So when you download it, hopefully it won't have that, but it didn't hurt anything to have that extra little grayscale option in there. Unless it was converting it to grayscale twice, I don't know. So that is our Xenity option. Let's look at one more option here real quick. So if I do files, thumbs. What that's gonna do is it's gonna open up this image viewer. And we can again, this one is a great option except for the way it works is kind of funky. You're going to go and select your photos or I guess M for Mark. So M and I'm gonna select the photos. If I wanna get a full size, I can hit enter to look at that. And again, down the bottom corner here next to this 26, you can see an asterisk. That means this image is selected. If I hit M again, you can see it's unselected, selected, unselected. I can hit space bar to go to the next one. And I can go through these and select the ones I want. When I'm done, I just have to exit out of the program and we'll process through them. So it's a good option, but if you don't know how it works, who would think to press M to select something, right? Let's look at the code though. Again, if you're writing this for yourself or workers that you're going to train on this, it's not a horrible option. Again, start off the same input, output, and it also creates the directory. And then we're going to run the image viewer that we're using. It's called SXIV, it should be in your repositories for most distros, I believe, at least it is for Debian. And so I'm assuming all Debian based distros. So we're running that and we're gonna say dash O. I believe is the option that allows you to mark and gives the output back to the script. And we're gonna say T is we're gonna start off in thumbnail mode. And then I'm giving it the directory I want to go to. So then when you exit that program, it's going to output all the ones you've marked. We're dumping into a while loop. Again, if none were marked, we're just gonna break. If not, we're gonna echo out. And you can tell that I copied this command from script to script. Cuz they're all basically the same scripts. So that's a quick look at those first three scripts. In the next two, we'll look more at the drag and drop options that I had there for you. So thanks for watching again. If you wanna look at these scripts, gitlab.com forward slash mail x1000 bash multi file select and you can see all these options here. In the next two, we'll look at the drag and drop options. Thanks for watching and as always, I hope that you have a great day.