Friday, November 16, 2012

A shortcut to launch a recent download

When download files in a browser, I prefer to save all the files to a specific location instead of allowing the browser to "open" the file. This means that to invoke the download I have to go to an Explorer window or command prompt and manually select/run the file.

So I chose to create a shortcut on my Quick Launch (yes I still use it in Windows 7) to automatically launch my "most recent download".

This isn't a particularly complex task or hard to figure out, but I thought I'd document it here anyway. There are probably better ways to do it too, but I'm most familiar with Windows Batch approaches to automation.

Step 1: Write a Batch File

I created a NEW_DOWNLOAD.BAT file and placed it on my system somewhere. The contents are:

@echo off

call :latest e:\download\*.exe ^
             e:\download\*.rar ^
             e:\download\*.zip ^
             e:\download\*.pdf

if "%LATEST%"=="" goto :eof
echo E:\DOWNLOAD\%LATEST%

if "%1"=="" "E:\DOWNLOAD\%LATEST%"
if not "%1"=="" copy /y "E:\DOWNLOAD\%LATEST%" "%1"
goto :eof


:latest
FOR /F "delims=" %%I IN ('DIR %* /B /O:-D') DO (
   SET "LATEST=%%I"& goto :eof
)
goto :eof



Basically what this does, is search my E:\DOWNLOAD folder for all .EXE, .ZIP and .RAR files, and launches the most recent one. You could add additional file types here if you wanted to.

Step 2: Add a Shortcut

I added a shortcut to NEW_DOWNLOAD.BAT and placed it on my Quick Launch bar. I configured it to launch Minimized, and gave it a custom icon from SHELL32.DLL to distinguish it. I also added a keyboard hotkey for the shortcut (CTRL-SHIFT-L.)


Step 3: Set it and Forget it

Now, when I download something, I just click on the Quick Launch shortcut or press my keyboard hotkey, and automatically my most recent download starts running.


For reference, I use a similar script now to "Display the most recent PDF file" in another folder, in combination with CreatePDF as my default print driver, to print/save and verify document output.