 So far we've looked at options where we run our script and we have some sort of file select option Through the script, but what we want to look now is drag and drop to our shell script So we have two options here on how to open up your whatever file manager you use Select a couple of files and drag them over and then have your shell script process them We're going to look at two different ways of doing that and so Let's have a look as mentioned in the previous two videos all the scripts We're looking at today are up on my get lab page get lab comm 4 slash metal x1000 and the project is called bash multi-file select Okay, we're going to drag and drop so if I wanted to I could pass Arguments or in this case file names to my script So I'm going to start off with my drag and drop to right I'm going to drag and drop to and then I could give it a file name. I can say temp My bw Photos again I purposely put spaces in the file names because that's what's going to mess you up and I can give it a file name Type it all out, but we don't want to type out every single file name, right? but if you have a file manager open and you select some files like those three I can drag and drop them here, and they drop them in which is great Now I can enter and it starts processing through them And now we have those three images in black and white or desaturated grayscale Let's look at that drag and drop to file It's shorter than our other ones right because we're just passing at arguments which is fairly simple I have my output directory You don't need the input directory because we're drag and dropping it from file manager Although as I mentioned in a previous video we could have our script open up your default file manager to that directory And that would be useful and save the user a couple of steps I didn't do that, but you'll see my notes here This script will allow you to drag and drop files even with spaces But single quotes apostrophes in the file names will not work. Okay? because Actually, would it would it mess up on this one that notes for the other drag and drop one Let's get that try Well, now I'm going off script here. Let me go ahead and just rename this one I'm gonna put an apostrophe in it, which you should never do with a file name and now Well, let's do it to two so we can process through at least two F2 Rename just add an apostrophe somewhere single quote whatever you want to call it and I will say files drag and drop to I Will hit enter. Oh, sorry. I will hit space. I'll select those two drag and drop. Let's see what happens Ah, so this one does work even with apostrophes in the name or single quotes, whatever you want to call them That's fine. So that's that's one of the benefits of this one thing is you got to know before you start the program to Drag and drop those files. So drag and drop them hit enter. It'll process through them Again, let's quickly look at this script And again, all I'm doing here is if I tried to originally and I tried to do something and it didn't work properly I Tried to loop through them You know item by item, but the apostrophes were screwing things up But I realized if I start with the first option I process it and then you can say shift and it'll shift the next one That fixed my problem with these single quotes. So this is super simple. I'm just saying while Basically, there is an option here process it Okay, go through it and then shift and one will be well then two will become one Then three will become one and you know, we'll move them all down. So I Did a horrible job explaining that but the code is pretty simple right there but Maybe you don't pass the files before the program starts or you want to give the user prompt to drag and drop the files or some other option we're going to Files Drag and drop. So the I showed you drag and drop to first. Let's go ahead and run this one This one actually says please drag and drop files now if I select a few of these here Let's go ahead and race our output so we know and I will grab a few of these Drag and drop them and then hit enter and it will convert them. No problem Great, but let's go ahead and drag then drop these ones with the apostrophes. I'm assuming they're going to fail I actually did not test this out. I'm 99% sure this is going to fail because I know how I wrote the script So we have to start our script Move to our file manager Drag it over here click back in the shell and hit enter and you can see we got problems And it's because of those apostrophes in the name so Why is that? Well, we have again we have our output we create for our output directory Then I'm just using the read command now. I tried different ways of doing this I tried doing read and you can dump it into an array and I still have the same problems I'm just gonna dump all the text into files Right, and then what do I need to do now? Look at when the files are dragged So let me open up a new shell down here actually now. Let's let's exit out of this I'm not even gonna have a command in there. I'm just gonna drag and drop these files here You can see this is the file and it's got quotation around it And then there's a space and then the quotation the next file name quotation space Next quotation so each one is separated by space, but has those single quotes around it, right? Well, I need to get rid of those single quotes the script didn't like those but I Need to get rid of them in a smart way that knew which quotes Were at the beginning of the file in a file So what I did ended up doing here is I ended up echoing the entire list and what I did was I said, okay Take all the quote single quotes with a space between them. So quote Space quote and make it converted to a new line The problem is the very first file will have a quote before it a single quote and the last file Will have a single quote for it. So then I deleted that So that there's my issue right there if your file name has a quote in it I'm deleting them all right there and that's the biggest drawback to doing this this way and if you know a better way Please let me know but then I can loop through them and do the same thing as before But that is the biggest drawback to the script parting of this is if there is a Apostrophe in your file name which some people do it's gonna mess things up, but This is the simplest way I came up with drag and dropping into a file and again I'm just using the read command which reads it all as text, but then splits it out by those spaces and quotes so None of my options are absolutely great, but they are all workable again FZF Definitely the best option for most files And again the only scenario I could think of where FZF is not the best option is When I'm working with photos because I want to see which ones I'm selecting or maybe videos because I want to look at the thumbnails of Which one I'm selecting but anything else FZF just wins hands down, but I thought I would come up with a few scenarios here and Show you how I came up with my solutions Let me know if you know another way to do it also visit films by chris.com. That's Chris the K There's a link in the description as always. I hope that you have a great day