Tutorial for external commands or plugins

2012-08-24
2013-01-29
  • Mert Nuhoglu
    Mert Nuhoglu
    2012-08-24

    Is there any tutorial that explains how to add external commands or plugins to destinations?

     
  • Jens Klingen
    Jens Klingen
    2012-08-24

    Hi mertnuhoglu,

    Currently not. At least none that I know of. We definitely have to update the help file on plugins before finally releasing version 1.0. Maybe we should also add an "Configure external commands" item to the main menu for better usability.

    How to configure the external command plugin, in short words:
    * Go to Settings > Plugins
    * Select "External command Plugin"
    * Click "Configure"
    * Click "Add" to add an executable (e.g. Photoshop.exe) which can then be used as screenshot destination, passing the image path as command line argument.

    Here you go. :)

    Is your question about the development of Plugins, too?

    Best regards,
    Jens

     
  • Wikinaut
    Wikinaut
    2012-11-27

    "Configure external command" does work for eg. calling "C:\mypath-to\PaintShop.exe" but does not work to my batchfile "c:\utils\ocr.bat"

    The batch file requires a written file and its filename as second parameter ( c:\utils\ocr.bat filename ).

    This does not work for me, Greenshot appears not to having written the file when calling my batch file.

    Please can you assist.

     
  • Jens Klingen
    Jens Klingen
    2012-11-27

    Strange… Greenshot does not make a difference between exe and bat files, it simply executes them.
    Are you sure that everything is configured correctly? Are you actually passing the file as an argument, using "{0}"?
    Keep in mind that you actually should put the double quotes around it, to avoid unexpected behavior in case of spaces in the directory path.

    If it does not work, you might also want to have a look at Greenshot's log file. You can easily access it: open Greenshot's "About" dialog and hit the letter L on your keyboard. There might be additional information in it, helping us to track the problem down.

     
  • Wikinaut
    Wikinaut
    2012-11-27

    Hello, here is my batch file. It resizes using ImageMagick(Convert) and then OCRs using Tesseract. But this does not work when being invoked by Greenshot as "External Command"

    It requires the name of the screenshot filename as first parameter, but this does not work with Greenshot. Where does Greenshot store its image so that my batch file can read it ?

    Remark: Greenshot does apparently _not_ store the image using the correctly set-up path and filename - no image present when using the External Command way.

    Perhaps you can help.

    @ECHO OFF
    REM OCR 20121118
    REM batch resize images 20121014
    IF (%1)==() GOTO HELP
    SET LANG=%~2
    IF (%2)==() SET LANG=deu
    SET TMPFILE=%TMP%\ocr.tiff
    setlocal EnableDelayedExpansion
    @ECHO OCRing %~1 (%LANG%) ^=^=^> ocr.txt
    @C:\Programme\ImageMagick\convert -resize "400%%" -type Grayscale +compress "%~1" %TMPFILE%
    @C:\Programme\tesseract-OCR\tesseract %TMPFILE% ocr -l %LANG%
    type ocr.txt
    GOTO EOF
    :HELP
    @ECHO:
    @ECHO OCR image
    @ECHO:
    @ECHO Usage^:    ocr x.jpg [deu^|eng]
    @ECHO:          default deu
    @ECHO:
    :EOF
    
     
  • Jens Klingen
    Jens Klingen
    2012-11-28

    Hi there,

    I do not have ImageMagick and Tessaract installed, but I made a test with this:

    @echo off
    echo %1
    if exist %1 echo found file
    if not exist %1 echo file not found
    

    which works as expected ("found file").

    Have you had a look at the Greenshot log file? The output of your batch is written to the log, so it should be easy to find out why it does not work.

    When exporting screenshots to external destinations, they are saved to the temp directory, e.g. on Windows 7 this is something like: C:\Users\USERNAME\AppData\Local\Temp

    Hope this helps, best regards,
    Jens

     
  • Wikinaut
    Wikinaut
    2012-11-28

    tl;dr: works - after adding absolute output filename (path) to my ocr.bat

    Using your test program, it's DOS box window pops up for 0.5 seconds and I could not read anything. Then I modified your program to write the output to a file with a determined path.

    First result: I found, that the result of a Greenshot call was

    File "C:\WINDOWS\TEMP\20121128_0821_C_utils_test.bat_Notepad_.png" found

    i.e. Greenshot uses the Windows TMP directory instead of the user-defined path.

    * Improved test program for checking external command feature of Greenshot:

    C:\UTILS\TEST.BAT

    @echo off
    REM @echo %1
    if exist %1 echo File %1 found > c:\utils\test.out
    if not exist %1 echo File %1 not found > c:\utils\test.out
    

    The second problem was in my OCR.BAT code, that the output of tesseract-ocr was written to OCR (tt adds TXT, so that the filename results in OCR.TXT) was written to elsewhere.

    I added %TMP%\OCR so that the output is now written to C:\windows\temp\ocr.txt and this _works_.

    Full script:

    External command script OCR.BAT for reszing and OCR-ing with TESSERACT from Greenshot:

    C:\UTILS\OCR.BAT

    @ECHO OFF
    REM OCR 20121128
    REM batch resize images 20121014
    IF (%1)==() GOTO HELP
    SET LANG=%~2
    IF (%2)==() SET LANG=deu
    SET TMPFILE=%TMP%\ocr.tiff
    setlocal EnableDelayedExpansion
    @ECHO OCRing %~1 (%LANG%) ^=^=^> ocr.txt
    @C:\Programme\ImageMagick\convert -resize "400%%" -type Grayscale +compress "%~1" %TMPFILE%
    @C:\Programme\tesseract-OCR\tesseract %TMPFILE% %TMP%\ocr -l %LANG%
    type ocr.txt
    GOTO EOF
    :HELP
    @ECHO:
    @ECHO OCR image
    @ECHO:
    @ECHO Usage^:    ocr x.jpg [deu^|eng]
    @ECHO:          default deu
    @ECHO:
    :EOF
    
     
  • Jens Klingen
    Jens Klingen
    2012-11-28

    Thanks for the update and for sharing the script with us :)

    Nice to hear that everything is working fine now.

    Best regards,
    Jens :)

     
  • Robin Krom
    Robin Krom
    2012-11-28

    It's very important to get the filename from your arguments, it would be wrong to expect it at a location.
    In the case you would expect it somewhere, your batch file would no longer function if you change your Greenshot settings.

    The file that is created in the external command plugin is a temp-file, and its even removed after ~10 hours.
    I have to admit that there is still some work to be done with the external command plugin, it should be easier to configure what happens with the written file etc.. but this is how it is currently!

     
  • Wikinaut
    Wikinaut
    2012-11-28

    It was not clear - because of lack of documentation - where the file (screen capture) is saved. So to be on-topic I also suggest that a short tutorial is written how the external command works.

    In my view it would be sufficient to have some lines of text in a new "Configure external command" section.
    Currently, there is only NEW, EDIT, DELETE, CANCEL and OK.

    So I suggest to add HELP there.

     
  • Jens Klingen
    Jens Klingen
    2012-11-29

    Okay, I thought it was obvious, the "Argument" text field being pre-filled with "{0}" and the label explaining what {0} means.

    but it's obviously not, so maybe we should add some more detailed information on this, you are right.

    Thanks for your feedback
    Jens

     
  • Wikinaut
    Wikinaut
    2012-11-29

    @Jens

    It was fully clear, that this is the filename. It should be however noted that the path/filename will be in %TMP% , and the external command must not rely upon relative paths, and must only use absolute fully specified paths.

     
  • Wikinaut
    Wikinaut
    2012-11-29

    In other words: for me, it's clear now, and this issue is solved "worksforme".

     
  • Robin Krom
    Robin Krom
    2012-11-30

    That's good to hear, we do need to have a look at how to make it more usable and logical.

    Best wishes,
    Robin