Download all images on a web page

I found the "execute javascript in front browser" and added this action:

const imgUrls = Array.from(document.querySelectorAll('img')).map(img => img.src);

To get all the image urls into an array. Now,k I want to copy all the images to the clipboard and I am lost. Is this something that can be done? How do I accomplish such a thing?

Thanks
odin

The approach I take is to download the images as separate files on my Mac's disk using the AppleScriptable app called Leech. To make things even simpler I've created a third-party plugin action for KM that sends URLs to Leech for downloading.

I'd be happy to share if not getting images into the clipboard is something you can live with!

Wait, you what? Very cool—please message me, we could distribute this on our site with Leech for those interested! (If you wouldn't mind, of course!)

-rob.

As an example here's a demo macro using your JavaScript with my KM plugin to download from the currently loaded web page.

Keyboard Maestro Export

When run on this web page https://pixelsnaps.photography it results in this in Finder:

image

I've just added information about my file-downloading plugins here:

Riffing off of @tiffle's macro, this works with curl.

download all images on webpage copy.kmmacros (7.4 KB)

1 Like

Wow! Thanks!

Thanks for this, @edjusted. I didn't think I needed (or even wanted) this but it's been fun to play with a version that works in the Front Browser.

I made a few changes:

  • Prompt for destination folder (and optionally create a new one)
  • Optionally filter the array to just JPEGs
  • Massage the array to eliminate brackets and quotes
  • Further massage the array to eliminate extra parameters (stuff following a '?')
  • Use a progress bar during the download instead of notifications
  • Eliminate the delay

Still a work in progress (I could add some filters, I suppose) but thanks again for the curl version.

Download All Images.kmmacros (10 KB)

1 Like

Very cool, @mrpasini !

For anyone who's interested, I also have another thread in this forum that goes into detail about issues dealing with destination paths with spaces, and an alternative to using curl.

Ah ha! I was looking for that discussion in this thread because I wanted to try the Get URL action (which is tricky).

Here's the Get URL version of the macro (which is a little smaller than the curl version):

Download All Images.km.kmmacros (9.8 KB)