Using AutoHotKey to Select the Last ScreenShot from Greenshot

I take a lot of screen shots in my work. They are invaluable in recording issues and producing software instructions and the like. To assist me with taking and saving screen shots I use Greenshot. I have it configured to not only copy the screen shot to the Windows clipboard, but also to save the screen shot to a specific directory.

I recently wrote a post (Using AutoHotKey and GreenShot for sharing screen shots to a shared folder) on how I use AutoHotKey to quickly share a screen shot with colleagues, but that isn’t the only AutoHotKey script I have for working with my screen shots. Another one I find useful is to open Windows Explorer with the last screen shot selected. This can be handy for dragging the file into an application, selecting it for editing, etc.

The script is relatively straight forward and is based around the use of the /select parameter that can be passed to Windows Explorer at the command line.

The script basically does three things.

  1. Get the file path of the latest file in the screen shots directory.
  2. Copy the file to the shared folder.
  3. Copy the shared folder file’s path to the clipboard (ready for pasting into the chat window).
;WIN+Capital S
;Open explorer at the last screen shot
;Get the file path of the last screen shot
strSourceFilePath = % GetLastScreenshot()

;Open explorer and select the last screen shot
Run, explorer.exe /select`,"%strSourceFilePath%"

;Function to get the path of the last screen shot file.

    fileList =
    Loop, %strScreenShotDirectoryPath%\*.%strScreenShotFileType%, 1
    fileList .= A_LoopFileName "`t" A_LoopFileTimeModified "`n"
    Sort, fileList, R

    strLastFile = % SubStr(fileList, 1, InStr(fileList, A_Tab))
    strLastFile = %strScreenShotDirectoryPath%\%strLastFile%
    return %strLastFile%

The script makes use of a function called GetLastScreenshot which returns the file path to the last screen shot saved to the screen shot saving folder. The function contains two variables that should be matched up to the Greenshot configuration.

  • strScreenShotDirectoryPath should be set to the folder used by Greenshot for saving the screen shots.
  • strScreenShotFileType should be set to the file extension used by Greenshot for saving the screen shots (e.g. PNG).
Author: Stephen Millard
Tags: | autohotkey | utilities | scripting |

Buy me a coffeeBuy me a coffee

Related posts that you may also like to read