Trying to add "move" to Convert URLs to PDF script

As titled, I’m struggling to add a move function to the Convert URLs to PDF AppleScript. I have the below so far, with the bold bit being the problem I think.
I basically have an RSS feed and as I go through, I want to trigger this script to convert to PDF and move to my Article folder in the same database.

PS. Second question, is there a way of triggering the full “Capture PDF Paginated” action (like from the cog above the internal browser) via script, as this renames the file with the title of the page and formats slightly differently to the above AppleScript (which doesn’t rename the file once captured)?

Thanks in advance.


tell application id "com.devon-technologies.thinkpro2"
	set theDatabase to current database
	[b]set theFolder to location / (Cab_Articles in theDatabase)[/b]
	set theSelection to the selection
	if theSelection is not {} then
		try
			show progress indicator "Converting..." steps (count of theSelection)
			repeat with theRecord in theSelection
				set theName to name of theRecord
				set theURL to URL of theRecord
				step progress indicator theName
				if theURL begins with "http:" or theURL begins with "https:" then
					set theGroup to parent 1 of theRecord
					set theCopy to create PDF document from theURL name theName in theGroup with pagination
					set creation date of theCopy to creation date of theRecord
					set label of theCopy to label of theRecord
					set state of theCopy to state of theRecord
					move theCopy to theFolder
				end if
			end repeat
			hide progress indicator
		on error error_message number error_number
			hide progress indicator
			if the error_number is not -128 then display alert "DEVONthink Pro" message error_message as warning
		end try
	end if
end tell

This is the common syntax for moving something

tell application id "DNtp"
	set theDestination to create location "/test"
	set theResult to move record (the content record) to theDestination
end tell

Because DEVONthink’s data structure is record-based (and groups are records) you need to “create” the location then “move record” to the created location. “create location” will not create a duplicate location if one with that path already exists – but it will assign the UUID of that location to the variable you specify.

I see. How would you recommend defining/using theResult below? Many thanks.


tell application id "com.devon-technologies.thinkpro2"
	set theSelection to the selection
	if theSelection is not {} then
		try
			show progress indicator "Converting..." steps (count of theSelection)
			repeat with theRecord in theSelection
				set theName to name of theRecord
				set theURL to URL of theRecord
				step progress indicator theName
				if theURL begins with "http:" or theURL begins with "https:" then
					set theGroup to parent 1 of theRecord
					set theCopy to create PDF document from theURL name theName in theGroup with pagination
					set creation date of theCopy to creation date of theRecord
					set label of theCopy to label of theRecord
					set state of theCopy to state of theRecord
					set theDestination to create location "/Inbox/Test"
					set theResult to move record (the content record) to theDestination
				end if
			end repeat
			hide progress indicator
		on error error_message number error_number
			hide progress indicator
			if the error_number is not -128 then display alert "DEVONthink Pro" message error_message as warning
		end try
	end if
end tell

What are you trying to accomplish?

Your script, above, will take a bookmark document, make a PDF from it, then move the bookmark to /Inbox/Test.

If that’s what you want to do, then that’s what it does.

You don’t usually need to do anything with “theResult” in this code:


set theResult to move record (the content record) to theDestination

it’s more or less a placeholder in the standard syntax. Also, the “content record” is the currently selected record – which is why the bookmark gets moved to “/Inbox/Test”. If this is what you want, fine. Otherwise … ?

At the moment, it creates the OCR’d PDF but in the same folder as the bookmark (in this case, the Global Inbox) and doesn’t move it to Cabinet/Inbox/Test?

At the moment, it moves the bookmark to /Inbox/Test and leaves the PDF behind. If you want to leave the bookmark and move the PDF instead then substitute


set theResult to move record theCopy to theDestination

for


set theResult to move record (the content record) to theDestination

Thank you very much! My issue was I was running this script on bookmarks in my Global Inbox and it was creating a subfolder Test in there, rather than in my chosen database. Running this from the my main database inbox works fine.

This is part of a larger plan, whereby I subscribe to my Pinboard rss feed (for a specific topic) and then convert those entries to PDF for long-term archiving. Does anyone know how to automate the “Capture PDF (Paginated)” action on an RSS feed, perhaps on a schedule?

(I’m aware of [url]Automatically convert html to pdf], but the Convert URLs to PDF script doesn’t pull down a bookmark’s page title and instead uses the last part of the URL, which isn’t very user friendly)

Current versions of DEVONthink do not have the ability to schedule scripts.

Actually, if you check the code you can see that the script is doing this


create PDF document from theURL name theName in theGroup without pagination

so the built-in script is using the name of the record, not “the last part of the URL”. I checked this on an RSS feed from NYBooks.com and it is working as expected. The created PDF has the name of the article in the RSS feed. It is not possible to get the display name that the feed item might have in a browser without adding additional scripting steps to open that item in a browser and get document properties from that. In other words, “the bookmark’s page title” is not a property that DEVONthink knows about (or, exposes in its scripting interface).