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:
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.
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.