Pause Until.. Download Is Complete

I'd like to start a file download and then wait until it's done downloading to do something else.

How can I do this in KM?

One possible way might be to wait for the file by looking at it. My instinct says there is a hidden file being used while a file is downloading, and that the file is deleted when the download is complete.

So I'd be waiting for that file to disappear before doing anything else. Something like this:

Is this how it works? If so, what's the file naming convention? If not, how can I do this in KM?

Turns out you can just wait for the file to exist if you know the path.

The file won't officially exist until it's done downloading.

1 Like

This depends on the behavior of the app that is downloading the file. So, you may have to adapt your macro if you use a different app for downloading.

You can use the shell command lsof (list open files) to watch the download directory and see if the browser has any open files there. If it does, there are ongoing downloads. If not, all downloads are complete.

In the example below, lsof -c safari generates a list of all files that are currently open by processes with names beginning with "safari." Pipe that list to grep and if the path of the download folder doesn't turn up, there are no ongoing downloads. The return variable lsof_out will be empty.

The three second wait after the check may or may not be critical to your application. It gives the browser plenty of time to do its post-download housekeeping before you start mucking with stuff.

This is easily modified to wait until there are fewer than some number of ongoing downloads before you start the next.

4 Likes

How to wait until Google Chrome completes?

With Google Chrome big files (maybe all, really) will exist as a temporary crdownlod file while it’s being downloaded, in the folder til file is being downloaded to.

Assuming that you know the folder and the file name, you should be able to test for the existence of the file with a if-action and “at this path” condition. To wait for an arbitrary time, I guess you can put this check inside a while loop that will continue until the file has been downloaded - at which time the temporary file name will be replaced with the correct file name.

1 Like