Jump to content

GreenShot Screen Capture Automation


AGlassman
 Share

Recommended Posts

GreenShot (http://getgreenshot.org/) is a nice, free for personal use, screen capture utility. It is designed to be running all the time (in the system notification tray) and triggered with a Global Hotkey (Print Scrn).

I prefer to only run it when I need it and have it exit when I'm done, so I wrote this simple script. It starts the utility (if it's not already running), triggers a capture operation, waits for me to finish editing/saving the image, and then closes the utility.

The only tricky part was determining when it was ready to accept a HotKey to start the capture. My solution was to monitor it's IO count.

The only downside is that it leaves the tray icon visable until the next tray refresh, because I killed it instead of closing it down normally. (Known problem).

- Alan G -

GreenShot_Auto_X86_V1.0.zip

; =====================================================================
;    Start GreenShot
;    Send it a PrintScreen keyboard commnad
;    Wait for a capture
;    Shut it down
; =====================================================================
    Global $ProcessName = "Greenshot.exe"                                                ; Process Name
    Global $WindowTitle = "Greenshot image editor"                                        ; Image Editor Window Title
    Global $RunCmd = "C:\Program Files (x86)\Greenshot\Greenshot.exe"                    ; Program run Command
    Global $WorkingDir = ""                                                                ; Working Directory

    ; If GreenShot is not already running

    If NOT ProcessExists( $ProcessName ) Then

        ; Execute GreenShot

        If NOT ShellExecute( $RunCmd, "", $WorkingDir ) Then
            MsgBox( 16, @ScriptFullPath & " - Error", _
            "Program failed to execute. $RunCmd = '" & $RunCmd & "'." )
            Exit( 1 )
        Else

            ; Wait for the GreenShot process to exist

            If NOT ProcessWait( $ProcessName, 5 ) Then
                MsgBox( 16, @ScriptFullPath & " - Error", _
                "Process did not start. $ProcessName = '" & $ProcessName & "'." )
                Exit( 1 )
            Else

                ; Wait for a minimum number of IO (So we know it's ready)

                Global $Ready = False
                For $i = 1 To 20
                    Global $IOStats = ProcessGetStats( $ProcessName, 1 )
                    If $IOStats[1] > 4 Then
                        $Ready = True
                        ExitLoop
                    EndIf
                    Sleep( 250 )
                Next ; $i

                If NOT $Ready Then
                    MsgBox( 16, @ScriptFullPath & " - Error", _
                    "Process IO Reads not > 700. $ProcessName = '" & $ProcessName & "', $IOStats[1] = '" & $IOStats[1] & "'." )
                    Exit( 1 )
                EndIf

            EndIf ; NOT ProcessWait
        EndIf ; NOT ShellExecute
    EndIf ; NOT ProcessExists

; Send GreenShot a PrintScreen Keyboard command to
; initiate a Capture

    Send( "{PRINTSCREEN}" )

; Wait for the Greenshot Image Editor Window to Open
; after I take a shot

    If NOT WinWaitActive( $WindowTitle, "", 300 ) Then
            MsgBox( 16, @ScriptFullPath & " - Error", _
            "Image Editor Window did not open. $WindowTitle = '" & $WindowTitle & "'." )
            Exit( 1 )
        EndIf

; Wait for the Greenshot Image Editor Window to Close
; then kill the process

    WinWaitClose( $WindowTitle )
    ProcessClose( $ProcessName )
    If NOT ProcessWaitClose( $ProcessName, 5 ) Then
        MsgBox( 16, @ScriptFullPath & " - Error", _
        "Process failed to close. $ProcessName = '" & $ProcessName & "'." )
        Exit( 1 )
    EndIf

; All done

    Exit( 0 )
Edited by AGlassman
Link to comment
Share on other sites

  • 2 months later...

Hi,

I am one of the Greenshot developers and just joined the AutoIt forum as I have plans to make some Greenshot functionality available to AutoIt (and other applications).

I noticed this post and I want to ask you what reason you have to stop Greenshot?

Will also explain you a better way to do this, but need to check this befor posting.

P.s.

Make sure you use the latest version, we are currently working on our 1.0 and a release candidate will be available soon.

Best wishes,

Robin

Link to comment
Share on other sites

Hi,

I am one of the Greenshot developers and just joined the AutoIt forum as I have plans to make some Greenshot functionality available to AutoIt (and other applications).

Very nice!

I noticed this post and I want to ask you what reason you have to stop Greenshot?

Probably due to the fact that nobody replied to the topic in these three months that have passed!

@AGlassman

Very nice work, thanks 4 shared...

Regards,

João Carlos.

Edited by JScript

http://forum.autoitbrasil.com/ (AutoIt v3 Brazil!!!)

Somewhere Out ThereJames Ingram

somewh10.png

dropbo10.pngDownload Dropbox - Simplify your life!
Your virtual HD wherever you go, anywhere!

Link to comment
Share on other sites

  • 6 months later...

I noticed this post and I want to ask you what reason you have to stop Greenshot?

I use a large number of utilities in the course of a day's work. Some, like GreenShot, only rarely and I don't want them running all the time. I realize that GreenShot takes almost no resoruces when it's idle, but I prefer to keep the number of active processes (and tray icons) to a minimum.

Link to comment
Share on other sites

I must admit to being a tad bewildered by this topic ... perhaps it hasn't really been thought through properly, or I'm just missing something.

In other words, I'm struggling slightly to come up for a plausible scenario for the Automation element.

I can understand leaving an App like Greenshot running, for a security purpose perhaps, but then you'd continue to leave it running, otherwise I'd just set a hotkey to start it or just manually run it at need.

On top of that, I'd avoid something like Greenshot and code my own solution, or just use/modify one of the many provided here over the years.

But then, perhaps Greenshot does something special, like notice when a specific window appears and react to it, taking a screenshot? I've built watcher programs myself, that do that, then shut down the PC ... possibly displaying the screenshot on next boot. Handy if a program doesn't have it's own shutdown option. Nothing like that has been declared though, so it seems unlikely.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

Ive used Greenshot for a few days then i re-installed my computer and forgot about it ts not a bad little utility.

@TheSaint its just a screen capture program but i liked the fact i could capture parts of the screen without the need of an editor and cropping, only thing that would of been nice was the naming of the file after maybe thats in there but i never really looked for it and use to F2 every file for the rename.

Link to comment
Share on other sites

@TheSaint its just a screen capture program but i liked the fact i could capture parts of the screen without the need of an editor and cropping, only thing that would of been nice was the naming of the file after maybe thats in there but i never really looked for it and use to F2 every file for the rename.

There are scripts here, that do all you want in that regard - a specific portion of screen &/or a specific window only. I use them in several of my programs.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...