Working with a newly downloaded file - Need some help

I've almost got a new macro written that will save me a ton of time, but I'm stuck on a couple of actions.

Right now the macro goes to a website and downloads a file.

I need to unzip that file, and then move it into a predefined directory.

I've tried a few ways to get a hold of the file, but I can't seem to identify it KM. As a slightly-primitive solution, I was thinking I could rename it to a set name, and then Move any files with that name to the defined directory, but I haven't been able to unzip, or even identify the newly downloaded file.

Here's a screenshot of what I have so far: https://i.imgur.com/snjREHp.png

Thanks in advance!

Welcome @Morgan_Crozier!

How about this:

It gets the most recently modified file in the Downloads folder and leaves its name in the Path variable.

You can then unzip it as shown.

(The Display action was for my benefit when testing - you can leave that out!)

1 Like

Amazing response, thank you!

The last step I'm stuck on: Would it be simple to move the unzipped file to a defined directory (this location never changes)?

I'm trying to figure out how to identify the new filename, and I don't quite understand how your solution was able to turn the most recently modified file in the downloads directory into a variable. My understanding is that it's looking for a Path (full file location?) in the Downloads directory, sorted by most recent, but I don't see where a variable is being set, just that it breaks from the loop.

Hi again @Morgan_Crozier,

In the example I gave you Path is actually a variable - it could be named anything you like. So if you put PotatoChips there then that would do, but then you'd have to refer to PotatoChips everywhere else and not Path.

OK - so I'm not great at explaining! Here's another example that not only unzips the latest file but also move the unzipped result somewhere else:


The first part is the same as I gave you already but you can see from it I've changed Path to File just to reinforce the message that it's a variable and could be named anything. The second part of the example then goes on to get the latest file's name into the variable UnzippedFile and then moves it somewhere else; I've called it ~/TheDirectoryOfYourChoice - you'll need to change that to the one you want!! By the way I don't know if the unzipped file will actually be a file and not a folder, so you may need to pay attention to that.

I haven't tested this example but I hope you'll get the idea.

2 Likes

For each loops create their own variable so that they can iterate multiple times with a new piece of data each time. The break from loop action conveniently exits the loop the first time it runs.

Amazing stuff, thank you so much. I've been using KM for ~3 years now and I find it incredibly useful, but I've clearly got a ton to learn still!

I've even managed to tweak the code to open the new file that's eventually generated from the terminal script. It's so nice! You've saved me a ton of keystrokes - my wrists are very grateful.

1 Like