2

Is there a way to trigger the built in Mac screenshot capture for page and area from a webpage? Manually I can trigger on my keyboard the

Command + shift + 4 or Command + Shift + 3

In my web app I have a button with a click event to "capture screen" I just want to attach to this click event to trigger the mac OS screen capture tool.

$(".captureScreen").click(function () {
    // Add Trigger here for Mac Screen Shot 
});

I can't seem to find any examples using JavaScript, maybe it cannot be accessed?

Redwall
  • 1,010
  • 5
  • 30
  • 55
  • possible duplicate of [Take a screenshot of a webpage with JavaScript?](http://stackoverflow.com/questions/60455/take-a-screenshot-of-a-webpage-with-javascript) – Sam P Jun 04 '14 at 08:14
  • 1
    Not going to vote to close as duplicate, because it is mac specific – Sully Jun 04 '14 at 08:49

2 Answers2

2

You can't, and there's a very good reason for that.

Imagine what would happen if this was possible, and somebody wrote a script that does this continuously, and as fast as possible...

A possible alternative is to use a java applett (or activeX control if you're not bound to OSX) to do this. You could start the applett / control from javascript and wait for its reply from javascript as well.

Note that this is not a perfect solution, as it will not work in mobile browsers or for people who have java turned off, or not installed, etc. It will also trigger a dialog box prompting the user to accept running the applett.

There are ways around this using HTML5 though, and i suggest looking in the thread Sam P posted.

Timothy Groote
  • 8,614
  • 26
  • 52
  • was also thinking, but couldn't I just trigger the keyboard presses on the keyboard `Command + shift + 4` to simulate a press which would fire the native screenshot on the Mac? – Redwall Jun 04 '14 at 08:21
  • No, Javascript is "sandboxed" in so much that it won't allow you to do things outside the browser window. The reasoning behind this is simple : security. If you could trigger OS functions from an anonymous web page by firing keypresses, that would be a gaping security hole. – Timothy Groote Jun 04 '14 at 08:23
  • Besides that, `Command + shift + 4` is not per se always the "take screenshot" combination. you can redefine it manually. – Timothy Groote Jun 04 '14 at 08:25
  • No problem :) hope you find a viable solution to your problem though. – Timothy Groote Jun 04 '14 at 08:32
0

I have not tried it, but this npm respository claims to be able to do it.

However, it looks like it is for use on your local machine only. Still, that is what I am looking for.

Obromios
  • 15,408
  • 15
  • 72
  • 127
  • That package is only relying on a shell script to call the same command you would if you pressed `printScreen` yourself, which after all is just a shortcut to an executable. It wouldn't work from the browser – ffflabs Nov 14 '17 at 17:54