I am automating capture of a selection of something like a portion of a web page and converting it to a PDF.
The easiest way is just to use the paste clipboard command:
tellapplicationid “DNtp” set clipboardRecord topaste clipboard convertrecord clipboardRecord to PDF document endtell
The results of that are often (perhaps even typically) disastrous. In the example below, for example, it gives me a 6 MB output file with two copies of the same set of images.
The other way is to create a new html page, open it, and paste the clipboard in by hand with ⌘V, then convert that to a PDF. The result is a nice little 300KB file that gets it right.
I don’t suppose anybody understands the ins and outs of the clipboard and scripting DT3 well enough to get results like the second example without having to actually open a window and script the interface to do the paste.
If you’re using Safari you could drag the selection to DEVONthink’s icon in the dock. That creates a clean webarchive. When you’re done with clipping select all webarchives and use Data > Convert > to paginated PDF.
You might want to take a look at this Smart Rule script if you want to create the webarchives in a group structure. But it’s just a workaroud, see below.
@cgrunenberg would it be possible to add a preference that toggles the resulting record type when dragging from Safari into a window? Currently it creates RTF(D), would be awesome if we had the choice to change that to webarchive which gives the best results over here.
A web archive of the selection? Last time I tested this the results were actually quite poor as the web archive provided by Safari for selection didn’t render as expected quite often.
Yes. The same result as if the Safari selection were dragged on the dock icon but instead of using the user’s default location create the webarchive directly in the group it was dragged to. Or to put it the other way round: The same behaviour as it’s currently when dragging into a window but create a webarchive instead of RTF. As a preference, of course.
Hmm, I guess the RTF result was even worse then? If I don’t want the whole page I’m almost always clipping via dragging to the dock, with very good results. Might be that it doesn’t always look exactly like the source but it gives nice clutter free results. I’m more interested in getting the best possible result than getting the exact same as most of the time that’s not really necessary.
This is what I see with a very small test. RTFs created by dragging into a window, webarchives created by dragging onto the dock.
I don’t use services at all for capturing as it’s necessary to trigger them via the menu bar once after Safari was launched before the assigned shortcut works (at least with macOS Mojave), and it’s not possible to “activate” the menu on Safari launch via Keyboard Maestro because the menu is only available if text is selected.
It would indeed be a far superior way to capture, unfortunately I never found a way to trigger services programmatically. Searching again I found NSPerformService but that seems to need the clipboard. Any way to trigger a DEVONthink service programmatically?
I don’t use services at all for capturing as it’s necessary to trigger them via the menu bar once after Safari was launched before the assigned shortcut works (at least with macOS Mojave),
How is this an issue when the shortcut persists after doing this?
Pressing a shortcut should execute the expected action, period. If this doesn’t happen it’s unexpected behaviour. It’s simply confusing until I figure out again that I have to manually activate the menu.
Turns out it’s easy to work around.
Create a Dummy Service in Automator.app whose only purpose is to be a menu item.