Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Get Image URL/Address from webpage selection using Applescript/Javascript

I need a quick way to get the image URL, just like I would get if I right click on an image and select "Copy Image URL". I'm thinking Applescript, though others have mentioned Javascript.


This needs to be compatible with an Automator workflow and needs to work with Google Chrome, Chromium, and Safari, at a minimum.


More specifics:


1. I already have an Automator workflow that this will be added to.

2. The workflow begins with text and images that I have selected on a webpage using the mouse.

3. The processing of the text is working fine.

4. I just need a Applescript or Javascript or Shell Script (which I assume are the only outside code that can be added to an Automator workflow) that will grab any and all image URL's within the part of the page selected in step 2.

5. Images are NOT downloaded. Only the image URL is needed.



The basic logic is this:


Does selected input contain images?

If yes,

get URL of image(s)

pass URL(s) to the next step

else continue

(Asked recently, but probably didn't explain it well)

Any help or ideas appreciated!

OS X Yosemite (10.10.4), 2.4GHz, 8GB Ram, 1TB HD, 256G SSD

Posted on Sep 1, 2015 11:45 PM

Reply
2 replies

Sep 3, 2015 3:56 PM in response to MattSh

Your request is far harder than you might imagine.


There is no automatic (identifiable) reference between an image buried in the middle of your selection and its URL.


Almost any external interaction with the selection will end up with the pseudo-rendered result (e.g. it may contain the formatted text and/or the images), but the links to the origin will be lost.


The alternative approach involves querying the document where you will be able to get the URLs of media, but there's no connection to the selection, so you won't know what is selected.


As a result I can't see any obvious way of doing this. Since JavaScript runs within the context of the page/document, you may have a better chance with that, but I don't have enough love for JavaScript to be able to help much.

Get Image URL/Address from webpage selection using Applescript/Javascript

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.