How to Save Pictures Under the Mouse Cursor? ... And Then Several!

Imagine the first page of a comic shown in a browser, let's say Safari.

I have manually saved the first picture, (named "01.jpg") in a directory I made especially and manually for this comic (let's say a directory named "supercomic"). Now I switch in the browser to the second page.

Now: Big outing of the macro. I navigate the mouse over the picture and press a hotkey. The Browser opens the right mouse-button menu and chooses "Save Picture As..." In the opening window the macro writes the new filename "02.jpg" and saves the picture in the already defined directory. The last action of the macro is, to add 1 to the counter, so the next picture saved will be "03.jpg".

I imagine another key-stroke-macro that sets the counter to "02" again.

That's what I want - but I have no idea, how to achieve this. It is not helpful, that the context-menu of Safari (or Firefox) offers the "Save Image As..." option not always on the same position in the menu, and it is also not helpful that the dialog itself is changing. It could be "Save Site As..." or no saving option at all.

Maybe I have the completely wrong approach - but what would be a better way?

I'd be grateful for every idea.

Best Regards,
Alfred

I am only addressing this little piece. The whole issue of maintaining a variable that moves from 02.jpg to 03.jpg etc. is certainly doable. You would want to put that value in the Clipboard so after the Save dialog appears you can, as part of your macro, paste that value in and then Save etc. If you select a folder and do everything manually for the first picture, it will default to that folder for the next event.

Anyway, this addresses ONLY this issue of selecting Save Image As … As you say, this phrase appears in different locations and may or may not be present at all. It is possible that there is a better solution than what I am proposing below.

I would consider using the "found image" option of Keyboard Maestro. It is sort of a last resort to use "found image" but in my experimentation, I could get it to work in this environment. The image is just a picture of "Save Image As …."

I used (Best) and 65% Fuzz and with these settings, it seemed to find this option successfully. If the words are not in the context menu then it just cancels the macro at that point. It does not matter where in the context menu Save Image As … occurs. I understand it, you would not want anything to happen if the one option were things like SaveSite As …

For whatever reason if I used Unique instead of Best, it failed.

I could not find an option in Keyboard Maestro to directly select Save Image As … in a context menu.

I think, alternatively, you can do: right click, copy (the image), then write the clipboard to file. You can, of course, prompt to type the file name before writing.

Hey Alfred,

Before I monkeyed around with the brute-force approach I'd see if I could parse either the entire source of the front page in Safari, or I'd try a more targeted approach with JavaScript.

I'd use Safari's (or Chrome's, or any other scriptable browser's) Developer Tools to examine the image in the given web page.

Then I'd see if I could get its URL via several approaches. If I could get the URL I could use curl to download it directly and rename it as desired.

Try running this when your comic is loaded:

Get Image Links in Front Browser v1.00.kmmacros (5.2 KB)

You should get a pop-up window containing image URLs that looks similar to this:

See if the URL for your image is contained within – then touch base.

-Chris

Hi @rlivingston and @stylebreak1

There is no need to use "Found Image" to do this. Once the context menu is invoked (by having Keyboard Maestro do a right-click press at 0,0 from its current location), just having Keyboard Maestro type the name of the item you want on the list (by using Keyboard Maestro's Insert Text by Typing) will select the item and then you can either stop the Macro there or have Keyboard Maestro press "Return" to invoke that item. See this from a previous thread on a very similar question:

THANK YOU ALL for your advice, hints and ideas. With your help I have now I solution, that works for me!
I call the result: "How to save a series of pictures in safari, when every picture is on a new site"
I'll give you the details now:

The solution consists of two macros and is tested only in the safari browser.

First of all: It is advisable to go to preferences of the FINDER and to checkmark "show all suffixes" (I don't know how this is written exactly, since I'm working on a German Mac. In German its "Alle Dateinamensuffixe einblenden". When this preference is made, you don't have to bother about the format of the image.
And it is a clever idea too, to go in the preferences of SAFARI and to choose in the common section for the value of "place to save" ("Speicherort für Downloads") the value "ask every time" ("Jedesmal nachfragen").

Now the macros. The first one is simply to initialize for a new series of pictures, that I want to save.

The first command initializes a global variable (it has to be global, because the action is repeated every time from the beginning).
Then I have added just an alert, to let the world know, that the variable is initialized and has a value of 1.

Before using the second, the main macro, you have to manually navigate your browser to the first picture you want to save, and to save it in the directory (that you probably create during this save) and to save this first picture as "001,jpg" (or 001.tif or 001.png - depending on your pictures). Then you navigate to the second picture of the series and hover the mouse over the picture.
NOW you can start the second macro. Here is it:

Bildschirmfoto 2021-03-30 um 17.04.13

"Move and right click" opens the context menu, normally shown when clicking the right mouse button.
"Insert text" is the exact text shown in the context menu. In German "Bild sichern unter ..." in English "Save image as ..."
The simulated "return" opens the saving dialog window. Fortunately the focus is already on the field of the filename, so the desired filename can be written with another "Insert text" - but before that the variable "GVar__MyCounter" is incremented by 1 AND with the additional option to format the result the 000-group gives leading zeros if needed.
After the already mentioned Insert text another return is simulated to close the file dialog window.
Last not least the user should know, that the action is terminated. This could be done with an alert. But since often the pictures in the browser are made as links, where a click leads to the next picture, I have simulated a left mouse click instead.
Since the opening and closing of the file dialog is time consuming the whole macro is saturated with pauses.

I hope, that someone finds this useful. And again: Thanks to all

1 Like