XYplorer: Copy Last Screenshot Here

Another quick but useful script for the Windows file manager XYplorer today when using it alongside my favourite screenshot application on Windows, Greenshot.

I use Greenshot to capture screenshots on my Windows laptop and as it does so, I have it configured to not only place the image on the Windows clipboard, but also to save it to a folder as a PNG file. This makes it really useful for referring back to later (which happens quite often) and for taking screenshots during online presentations. No pasting images into a Word document for me!

Sometimes however I need to grab a copy of the last screenshot as a file and drop it in a particular folder. This is useful when I need to capture and file away evidence of something. Typically something to do with bugs or system errors. For this reason, since I’d be in XYplorer anyway, I decided to create a simple script to smooth the process.

Whilst I’ve actually defined an XYplorer alias of `@ss` for the `Screenshots` folder to make it quick to access the screen shots folder I have Greenshot save to, it simply isn’t something I’d describe as quick. Opening a tab, typing in the alias, scrolling down to the bottom of the vast numbers of screenshots that tend to accumulate before I archive them, select the file, copy it, switch to the other tab, paste it in, it is so S - L - O - W. Particularly when I can have the computer carry out the activity in a much quicker way.

The script is so simple in fact I could almost have written it in the time it would take me to do that.

"Copy last screen shot here"
    $listFiles = listfolder("C:\Users\sylumer\Pictures\Screenshots\", "*.png", 1, <crlf>);
    $listFiles = formatlist($listFiles, r, <crlf>);
    copyto "<curpath>", gettoken($listFiles, 1, <crlf>);

The first line is simply a name I gave to the script. The second line however is more “functional”. It creates a new line (carriage return & line feed) separated list of PNG file paths contained in the screenshots folder I have Greenshot save the screenshots to.

The third line then sorts the list into the reverse order. Now the key point here is that this is putting the latest screenshot to the top of the list. How? Well, I have Greenshot configured to save the PNG files with a particular file name format.

${capturetime:d"yyyy-MM-dd-HH.mm.ss"}-${title}

As you might be able to guess, the first part of the file name is a time stamp of format yyyy-MM-dd-HH.mm.ss (e.g. 2000-01-02-03.44.55). This means that when sorting in reverse order in the screenshots folder, the latest screenshot will always be the first file.

The last line picks the first file path and then copies that file to the current folder of the active tab.

Simply add the script to whatever trigger location you want (a button, a catalog entry, a keyboard shortcut via user command) and away you go. Whilst you would have to use XYplorer to do this, you could certainly apply the approach to any screenshot capture tool that can save screenshots with a capture timestamp prefixed to each screenshot’s file name.

Author: Stephen Millard
Tags: | utilities | xyplorer |

Buy me a coffeeBuy me a coffee



Related posts that you may also like to read