Command Line to take Webscreen Shots

I have a template where the width is known. The height of the page may vary depending on the amount of content, e.g.,

I would love to find an Apple Script, command line add, something that I can trigger in Tinderbox to save a png of the page with as little whitespace around the border as possible.

I think this will require exporting the file to a know location and telling the app to view the page in a browser, and then grabbing the picture. Does anyone have any thoughts on what I can use to do this?

Automator has a ‘take screenshot’ module and it has a option to use an on-demand size (i.e. user set).

You ought to be able to make a script or quick action, invokable via a shortcut or the OS scripts menu to do this. The screengrab saves to the OS clipboard by default but you could add a module in Automator to either autosave the image or call a save dialogue for the user. The process uses Apple’s (in the /Applications/Utilities folder), though the latter does have a AppleScript dictionary ot its own - use it via Automator.

I don’t have them but I suspect apps like Snaggit or Camtasia might have sriptable features.

If the image is small enough to be viewed completely (i.e. no scrolling) in the Tinderbox preview pane, then you could invoke the script form inside Tinderbox, drag select the part of the screen to gab and the rest be automated.

[Note: I’m putting this up here as I don’t have time to make it but the info might give others the ingredients to make such a ‘quick action’).]

1 Like

Turns out there might be an easier way, as the Apple screen-grabbing utility can be called from the command line.

Paths & Permissions. Unless you’ve given Terminal “Full Disk Access” in system Preferences, don’t try to use full paths or ~-based ones. The Tinderbox default is your home folder, though run command and stipulate a different one. Otherwise, us a relative path from your home folder (and all folders of which exist!). So, to save to the Desktop use Desktop/file.png and not ~/File/file.png.

See the utilities man page for options. As the plan is to take a user-defined shot you must use the -i option. Two others are useful. -d gives a UI dialog with a message if there is an error, e.g. as above with OS write permissions. -x is useful if you want no feedback sound from the screen grab action.

Format. Grabs default to a PNG, though see the man page if you need other formats. The PNG is likely lightly compressed so you might want to pipe the image to something like imagoptim via its command line.

The demo file below has two stamps. The first makes a PNG in your hoe folder . It replaces spaces in the stamped note’s $Name with underscores and writes the string passed to runCommand() into the $Text of a note ‘log’, for error checking.

Stamp #2 does the same but adds a path element, writing the file to the Desktop, by way of further example.

Note the stamp’s work with the all 3 of the text view panes: text/preview/export, but not that the whole area to be captured must be visible on screen before initiating a grab (i.e. no scrolling which grabbing).

Here is the test file: screengrab-demo.tbx (212.6 KB)

@satikusala, I think this gives you the core structure that you can enhance for your process, e.g. more complex file name or path, as everything can be done in Tinderbox and then passed to the command-line. Much easier than Automator in the end!

For those old enough to remember, the mighty Price Noggin was one of Oliver Postgate’s creations.

1 Like