I’m very new to Keyboard Maestro and I’d like to get some help with setting up a macro that does the following:
Select links on a webpage
Convert the pages into PDF
Save them with a meaningful title to Dropbox
I’m currently using a workflow in Workflow.app on my iOS devices that does exactly this. I use it to take a bunch of newsletters I like and convert them to PDF. The problem is that it only works with Safari (I prefer Chrome), and the operation times out when the device goes to sleep.
If someone can start me off or point me in the right direction, I’d be super grateful.
Yes I did know that and I’m now trying to wrap my head around the macro that Peter posted. The part that I’m getting stuck is figuring out how to select the list of links, get their URL and open up each page. I can figure out how to save them to PDF after that.
Can you help me figure out where I'm going wrong? I'd also like to know how to debug macros going forward!
Any help is much appreciated. I'm learning slowly and I appreciate the assistance from the forum. I'll share the completed workflow once I'm up and running.
OK, based on all of the follow-up info you have provided, I think the below macro should work. Please note that I cannot fully test it because I do NOT have access to the main web page you want to use: https://club.macstories.net/newsletter-archive/
However, I have fully tested it on other web sites, and it works for them.
But, you may need to make some adjustments.
Also note that I have tested this ONLY on Keyboard Maestro 7.3.1 (7.3.1) on macOS 10.11.4.
If you run into any strange problems, please post the details/screenshot, and I'll try to help you debug/fix them.
Please feel free to ask any questions about the macro and/or my approach.
After saving each web page as a PDF, the following are displayed:
Many many thanks for taking time out to help me figure this out. It is obvious you have a great deal of expertise and mastery of CS fundamentals and concepts.
I by no means claim to be an expert in any of this so I truly appreciate the time and knowledge that experienced folks like you share.
I have a few questions about why you are doing some of the things that you are in the macro so that I can learn along the way:
What is a semaphore lock and why and when do you use one?
Is there any particular resource that you can recommend about how to debug KM macros?
What is getting written to the global KM variables that you have to delete them after the link block gets processed?
Reading through the macro it is abundantly clear that what I was trying to achieve was way out of my expertise, since this involves a fair deal of AppleScripts. Could this have been achieved without the scripting portion of the macro?
Are there any best practices of when to use JXA, AS, JS, Python, Shell etc for achieving a particular result, or is the choice mainly dictated by what one knows? I would like to start somewhere and would like to know if you have any recommendations for a language to use with KM to achieve some of the wonderful things it can do.
Are there any resources for JXA and AS in particular that you’d recommend for people starting out?
Once again, many many thanks for helping figure this out.
No problem, glad to answer them. Most likely others with have the same questions.
It prevents the execution of another trigger of the same macro, until the current execution completes. This macro can take a while to complete, so I did not want another trigger of it to happen while it was executing.
The primary reason for deleting KM Variables used in a Macro is to remove clutter from your KM Variable list. If the Variables are not needed later, they just get in the way.
Actually, I think there are only 3 scripts, and all are needed.
They are the best way to accomplish the objective, and I don’t know of any KM Actions that could have replaced them.
If there is a KM Action that will accomplish my objective, I always try to use that. I only revert to scripts if it can’t be done, or done easily/effectively with non-script KM Actions.
I generally stay away from Shell Scripts, mainly because of my ignorance about them, but also because they are harder, generally, to customize, unless you are an expert. A small change in a Shell Script can lead to loss of data if you are not careful.
I think each of us uses the scripting language we are more familiar with and most comfortable with. I know AppleScript the best, but I’m trying to to learn and use JXA as often as I can. If you don’t know either AppleScript or JXA, then I’d recommend starting with JXA.
The name of the semaphore can be anything. It just needs to be unique - in other words, you don’t want another Semaphore action to accidentally use the same name. But even if another one did use the same name, it would only matter if both macros ran at the same time.
If you want to know more about Semaphores, just ask. I have a personal affinity for Semaphores, having done a ton of multi-threading work in my life. You don’t need them very often, but when you do need them, they’re way awesome!