Importing PDF created by Safari—DEVONthink gets the wrong URL

Not sure if this is a bug exactly but it’s something that has caused me a headache over the past couple of hours.

I’ve created a Keyboard Maestro macro that does the following:

  • Exports the current Safari page via Print -> Save to iCloud Drive (which puts the PDF in Preview’s iCloud Documents folder)
  • Runs a simple script that imports that PDF to DEVONthink, and sets the URL
  • Closes the tab once completed

Here’s the script:

tell application "Keyboard Maestro Engine"
	set thePath to getvariable "filePath"
	set theTitle to getvariable "pageTitle"
	set theURL to getvariable "pageURL"
end tell

tell application id "DNtp"
	set theGroup to get record with uuid "[uuid]"
	set theRecord to import thePath name theTitle to theGroup
	set URL of theRecord to theURL
end tell

The problem I’ve encountered is that DEVONthink seems to automatically set the URL for the PDF from what the currently open tab in Safari is. If I remove the set URL line, it still grabs the URL from Safari, without being told to.

The problem is that DEVONthink does this after the tab has closed (thus it gets the wrong URL) and after my script has run (so it overwrites the URL that my script has given it with the wrong one).

There is, of course, a simple solution: adding a delay to the script, between the import and set commands, which means that the incorrect URL will be overridden with the correct one (instead of vice versa). Alternatively, I could add a delay to closing the tab. The problem is that this becomes a hack based on guesswork, and it’ll inevitably go wrong at some point. The macro/script either becomes unnecessarily sluggish with the extra delay or, with a short delay, it risks breaking at random.

A better solution (if I have inferred DEVONthink’s behaviour correctly) would be that it should only ‘guess’ the URL for the exported PDF if no URL currently exists for that record. Then the correct one wouldn’t be overwritten.

Thanks for the report! It’s indeed a bug, the next release will fix this.


Glad to hear it! :slight_smile: