Automatically pulling PDF from webpage into DevonThink 3

Hello everyone, I have a problem that I could not solve so far. I have a subscription to a magazine that publishes every Friday. Subscribers can download the PDF Version once it is published. To get to the correct PDF I need the following variables:

  • Year
  • Week of the year
  • my personal token

So the URL to get to the respective PDF would be as follows:[year]/[week of the year]?token=[my personal token]

I would like to set everything up that every Saturday automatically the PDF gets saved into a group in DevonThink 3.

I have the following tools at hand:

  • Keyboard Maestro
  • Shortcuts
  • DevonThink itself

Maybe anyone has an idea how to set this up…


Definitely possible.

First, though, does the magazine not provide an RSS feed for this? If so, it’d be the easiest option. (If it does provide RSS but truncates the content, there’s a good solution for that here.)

Aside: you may be interested in the PDF saving Shortcut I use, written up at the below link.

No, RSS is unfortunately not possible. That would have been too easy. :slightly_smiling_face:

Thanks for the Shortcut though.

I hope there is another way.

Sure. I think I would create a Keyboard Maestro macro that runs weekly on Saturday, some time after the PDF is guaranteed to have been made available. DEVONthink’s Downloads Manager is scriptable, and getting it to download a file is very simple:

tell application id "DNtp"
	add download ""
	start downloads
end tell

So pseudocode for a KM macro would look something like:

Set variable theYear to %ICUDateTime%yyyy%
Set variable theWeekNumber to %ICUDateTime%w%
Set variable personalToken to [personal-token]
Run AppleScript With Specified Parameters
    tell application id "DNtp"
	add download ""
	start downloads
end tell

I don’t recall offhand how to include parameters in KM’s AppleScript With Parameters actions, but I can poke around at it this weekend.

(I haven’t tested this, of course.)

Actually getting that file and moving it to a group would be more work. I’m not sure if it’s possible to get the downloaded file in scripting offhand, so I think you’d have to ask the Global Inbox’s Downloads folder for the most recent downloaded file after waiting a bit, then move it to a scripted location. This would be a little wonky in my opinion, so I’d probably just download it to the inbox and move it when I saw it.

1 Like

I was not aware how to get DT to download the file when pointed to a URL - thanks for the Apple script. I had set up the first part of the KM macro already. I will try to work in the apple script this weekend and keep you updated.

1 Like

It worked!

Here is the script to use the KM variables in the Apple script.

tell application "Keyboard Maestro Engine"
	set jahr to getvariable "Jahr"
	set ausgabe to getvariable "Ausgabe"
	set zugang to getvariable "MeinToken"
end tell

tell application id "DNtp"
	add download "" & jahr & "/" & ausgabe & "?token=" & zugang & ""
	start downloads
end tell

Tank you for your help!:+1:t2: