I want to create a macro to print to PDF → download that I can trigger every time I visit a web site (usually an article) I want to "print" (save as PDF).
Everything works perfectly: I trigger the extension → using KM, I press the PDF button.
I am unable to:
Trigger Extension Print Friendly & PDF using the native keyboard shortcut.
Click on PDF which works with the KM action click on button "PDF".
Image detection is working for me, with the default action settings. Have you included a "Pause until..." that image is visible, to account for the PDF's preparation time?
For better JavaScripters than me -- it's a link rather than a button. This is the code when the download is ready:
Thanks very much for giving my problem some thought, and all your efforts.
The macro does not work.
KM Engine LOG does not recognize pdf_1679054582_599fc4A4.pdf which makes sense because it is web site specific, ie the web site you used when you tested the shell script.
How could I convert that portion of the shell script into a generic format?
The code snippet I posted is (part of) the HTML code for the "Download" link -- the span bit you gave just formats the text, and (probably) can't be used as the element identifier. Someone who knows JavaScript (which isn't me!) might be able to use those listed classes to identify and "click" the download link.
Can you upload a sample macro of your step 2 "click on PDF" through to the "click on found image, which isn't working". As I said, the image worked fine for me on Safari -- if I can compare yours and mine I might be able to come up with something.
I wouldn't -- that whole area is "active", so use it all (just in case there's a clash with the smaller part from something else on your screen). This was working for me, albeit in Safari, with "Click at (0,0) relative to found image's center":
I was just opening the site (https://pdf.printfriendly.com) and using the form there -- I daresay the plug-in just automates that bit, submitting the form info directly.
But you should be able to do this directly with KM:
I installed the extension in Google Chrome 111.0.5563.64 on macOS 10.14.6.
I was able to give it a keyboard shortcut, and the shortcut works with no problems.
These work when run from the Dev-Tools in Chrome, but Chrome-Extensions are sandboxed – and these won't work when run via Apple Events (ergo KM's JavaScript actions or AppleScript).
Print to PDF Button Ref:
document.querySelector("#pdf").click()
Download your PDF Button Ref:
document.querySelector("#pf-dialog-pdf > div > div:nth-child(1) > a > span").click()
The upshot of this is that you may think after testing in the browser that the JavaScript will work in Keyboard Maestro, but you'd be wrong. Several people have pulled their hair out because of this...
@Nige_S thank you very much for your macro which works perfectly in safari.
In Chrome, I am back to square one. None of the found image actions worked, exactly as they did not work for me. It does not make sense but I tested a million times and variants. Exactly as per my initial post.
As per my initial post
in chrome I can simply use the press button action for PDF
the only step remaining is to press the last download button. Nothing works.
question for Chris
How would I use this information in a KM action ? what would I write in the field below or would I use another action ?
If it's not possible, is there any way to use the fact that the download button has a striking green color ?
In the meantime, I am using maximize window → triple click at absolute position which usually works.
Last question and I shall leave you in peace: I notice that long press is the most reliable way to click on download. As a substitute I am using triple click. Is there any way to long press at given location ?
IIRC you used to be able to put JavaScript snippets in the browser Favorites bar (bookmarklets?). Do those suffer from the same sandboxing restrictions? Could that be a possible approach to this problem (it looks like everything's constant, so no variable passing from KM etc)?
Mmm... not really a user of Chrome extensions,
and my assumption has always been that their evaluation space is deliberately inaccessible from that of the browser's document display tabs.
I've done a little more testing, and I'm all but certain my failure with the print button was due to sandboxing and not my own mistakes.
I thought there might be a sliver of a chance that a JavaScript bookmarklet could bridge the sandboxing between document and extension, but I've proven to my own satisfaction that this is not the case.