

Using the CASE statement in a Shell script to move files based on a condition
#Keyboard maestro download download#
For that, we can add a bit more scripting to handle more conditions as text.īy adding another Execute Shell Script block after the download is complete, we can use the CASE statement to determine what file we have and where it should go. This works well, but can be a little hard to manage if you need to dozens of file types or conditions. Combining blocks allows you to move different files around as they come into your Downloads folder. pdf, or contains “Unix” or whatever you are working with. The IF block can be repeated for each type of file you want to work with.

%TriggerValue% is the name of the file that changed in the Download directory.Īs shown, if the filename contains “sql” it will be moved to the chosen location. Using the built-in Keyboard Maestro IF-Then condition, we can move the file %TriggerValue% to a directory. When the variable is empty, the file is complete and we can proceed. If “grep” returns a result, the file is still downloading. Moving files using the Folder Trigger and IF condition in Keyboard Maestro I have another macro when using DevonAgent. So, change this as needed for the browser or application you choose. The Keyboard Maestro example uses Safari. In my example, I’m checking to see if Firefox has any open files. To compensate, we can add some scripting.īorrowing a very cool solution from Jeff Hester on the Keyboard Maestro forums, we can use LSOF (List of Open Files) to see when a download completes. The macro may trigger before the file is done. We also want to choose, “Ignore partial or changing files.” For most applications this works fine. The first thing to do is set up a “Folder Trigger.” For this example, it’s on the Downloads folder. With a combination of Keyboard Maestro and some Shell Scripting, I can move downloaded files around to keep things tidy. Since I have Keyboard Maestro, I can emulate a lot of that functionality.Įnter the Monitor Download Folder macro.

That’s more than Keyboard Maestro, Scrivener, and a few other tools. It’s a great program to help organize your files and put them where they belong. When you search for folder organization, you can’t help but find Hazel. ApMonitoring the Downloads folder with Keyboard Maestro
