Using AutoHotKey and Greenshot for Sharing Screen Shots to a Shared Folder

In my work I regularly have need to take screen shots and to make the process of taking screen shots easier I use the open source utility Greenshot. I have Greenshot configured to not only copy the screen shot to the Windows clipboard, but also to save it to a screen shots directory.

This configuration lets me cover the majority of my use cases, however one thing I find myself needing to do regularly is to share a screen shot with a colleague. This involves copying the (latest) screen shot to a shared folder and putting the file path to the file in a chat window. In order to speed up this process I created an AutoHotKey script to help me.

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).
;Run by pressing WIN+.
;Copy last screen shot to shared folder and resulting file path to clipboard
#.::
;Get the file path of the last screen shot
strSourceFilePath = % GetLastScreenshot()

;Copy the file to the shared folder
strTargetDirectory = x:\temp\
FileCopy, %strSourceFilePath%, %strTargetDirectory%, 1
soundbeep 37

;Copy the new file path to the clipboard
SplitPath strSourceFilePath, strFileName
clipboard = "%strTargetDirectory%%strFileName%"
soundbeep 200

return

;Function to get the path of the last screen shot file.
GetLastScreenshot()
{
    strScreenShotDirectoryPath=C:\Users\sylumer\Pictures\ScreenShots
    strScreenShotFileType=png

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

The calling script itself also contains a variable called strTargetDirectory. This is set to the path of the shared folder to which the screen shot is copied.

Author: Stephen Millard
Tags: | autohotkey | utilities | scripting |

Buy me a coffeeBuy me a coffee



Related posts that you may also like to read