Screenshot Active Window

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: JRL, Dorian (MJT support), Phil Pendlebury, Rain

Post Reply
User avatar
Dorian (MJT support)
Automation Wizard
Posts: 583
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Screenshot Active Window

Post by Dorian (MJT support) » Fri Jan 13, 2017 9:06 pm

I've recently made some changes to this, so I've deleted the old thread and am re-posting.

In my role as customer support, I often need to send screenshots of one particular window.

This script will :

  • Detect the active window.
    Calculate the size and location of the window.
    Screenshot only that one window.
    Save the screenshot as Screenshot-YYYY-MM-DD-HH-MM-SS.bmp
    Open the screenshot in folder (optional) for easy dragging and dropping.
    Open the screenshot in Paint (optional) for easy editing.


Just make sure to assign it a hotkey.

I use it daily, and I hope it helps you as much as it's helped me. :)

//Note. Make sure to assign this macro a Hot Key.

//Show the screenshot in Windows Explorer? yes/no
Let>ShowInFolder=yes

//Edit the screenshot in MS Paint? yes/no
Let>EditFile=no

//Get the active window
GetActiveWindow>ActiveWin,Xpos,Ypos,Width,Height

//Calculate the window size
Let>BottomRightX=Xpos+Width
Let>BottomRightY=Ypos+Height

//Get time and date for the filename
Year>TheYear
Month>TheMonth
Day>TheDay
Hour>TheHour
Min>TheMin
Sec>TheSec

//Set file path and name
Let>FilePath=%USERDOCUMENTS_DIR%\Screenshots
Let>FileName=%FilePath%\Screenshot-%TheYear%-%TheMonth%-%TheDay%-%TheHour%-%TheMin%-%TheSec%.bmp

//Create the output folder if it doesn't exist
IfNotDirExists>%FilePath%
CreateDir>%FilePath%
Endif

//Capture the screenshot
ScreenCapture>Xpos,Ypos,%BottomRightX%,%BottomRightY%,%FileName%

//Show the screenshot in Windows Explorer if ShowInFolder = yes
if>ShowInFolder=yes
RunProgram>Explorer /select,%FileName%
Endif


//Edit the screenshot in MS Paint if EditFile = yes
If>EditFile=yes
RunProgram>msPaint.exe %FileName%
WaitWindowOpen>Paint*
WaitReady>1
WindowAction>1,Paint*
Endif

  View Snippet Page
Yes, we have a Custom Scripting Service. Message me or go here

HSEIVANE
Junior Coder
Posts: 33
Joined: Thu Jan 02, 2020 2:52 am

Re: Screenshot Active Window

Post by HSEIVANE » Fri Jan 17, 2020 11:58 pm

Is it possible to send every screenshot by gmail?
and add the macro name to the screenshot?

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 583
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Screenshot Active Window

Post by Dorian (MJT support) » Mon Jan 20, 2020 10:15 am

Yes. SMTPSendMail, and send the image as an attachment.

I think you'll find it useful looking at the System Variables at the bottom of the Command Reference. Reading that is a goldmine of information and may just open up a whole new world for you. Script_Name is probably the one you want, but I'd encourage you to look at the list as there are others there which may help you.
Yes, we have a Custom Scripting Service. Message me or go here

HSEIVANE
Junior Coder
Posts: 33
Joined: Thu Jan 02, 2020 2:52 am

Re: Screenshot Active Window

Post by HSEIVANE » Mon Jan 20, 2020 1:24 pm

I just tried Script_Name but it doesn't insert it in the file name.

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 583
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Screenshot Active Window

Post by Dorian (MJT support) » Mon Jan 20, 2020 4:16 pm

How about %script_name% ?
Yes, we have a Custom Scripting Service. Message me or go here

nodochau
Pro Scripter
Posts: 56
Joined: Wed Jan 16, 2019 12:59 pm

Re: Screenshot Active Window

Post by nodochau » Wed Jan 22, 2020 3:30 pm

Dorian,
Thank you a lot for your share.

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 583
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Screenshot Active Window

Post by Dorian (MJT support) » Thu Jan 23, 2020 10:21 am

nodochau wrote:
Wed Jan 22, 2020 3:30 pm
Dorian,
Thank you a lot for your share.
Always a pleasure. :)
Yes, we have a Custom Scripting Service. Message me or go here

Post Reply