1

I'm trying to follow this guide and countered a problem with step 4. This step essentially binds a keyboard shortcut to a bash script that uses scrot and xclip to save a screenshot and pastes the saved location to clipboard.

If I were using a Linux operating system I could follow this instruction, but currently I am using a Docker Ubuntu Container hosted on Windows 10. If I try to use xclip or scrot I get the following errors respectively.

xclip error:

Error: Can't open display: (null)

scrot error:

Can't open X display. It *is* running, yeah?

To work around this I've thought about replicating step 4 on my host machine with a combination of snip & sketch, clip, and binding a window shortcut to a batch file. There are many issues with this, the main issue being the fact that snip & sketch doesn't automatically save your screenshots, so I'd have to manually save after each screenshot.

My goal is to save a screenshot to a specified location and paste the saved location into my clipboard. Emphasis on image location because I am aware that snip & sketch copies the screenshot onto your clipboard; this is a problem I can't paste an image into vim.

To perform these series of commands on Docker or my host machine is fine.

romainl
  • 186,200
  • 21
  • 280
  • 313
  • 2
    Maybe you can check https://superuser.com/questions/75614/take-a-screen-shot-from-command-line-in-windows for another tool to take a screenshot from the command line and autosave it to a file – leaf May 27 '21 at 05:01
  • @leaf, really helpful comment. I resolved the crux of my issue with this [batch file](https://github.com/npocmaka/batch.scripts/blob/master/hybrids/.net/c/screenCapture.bat). The only issue now is how would I modify the batch file such that I can specify the area to take the screenshot, rather than taking a screenshot of my entire screen/application? – user15988226 May 27 '21 at 17:04
  • The batch file actually runs C# code to capture an image from the active window area. You could start from line 58 `private Image CaptureWindow(IntPtr handle) ...` – leaf May 28 '21 at 01:33
  • 1
    Copying/Editing code from this [post](https://stackoverflow.com/questions/3123776/net-equivalent-of-snipping-tool), I think I have an idea on how to fully implement this. I'll post my implementation here when I finish in case another user has a similar question. – user15988226 May 28 '21 at 03:46

0 Answers0