The number of Pages in a pdf as custom metadata

I have been trying to the number of pages in a pdf to be available as a custom metadata.
I am not expert in AppleScript. The following is not working for me. Can sb help me with it please?

tell application id "DNtp" 
	set theRecords to get the selection 
	repeat with eachRecord in theRecords 
		set thePageCount to page count of theRecords
		add custom meta data thePageCount for "Pages" to theRecords
	end repeat
end tell

You have to use eachRecord (exactly one record), not theRecords (a list of records) inside the loop.

1 Like

Yes, that worked. Thank you.

On a side note: I applaud you exploring AppleScript. Learning to automate things is a wonderful, though sometimes frustrating, pursuit. But in the end, you can lean back and enjoy the fruits of your labors :slight_smile:

That being said, this is also an instance where someone who doesn’t want to tackle scripting could effectively use a batch process or smart rule using the Page Count placeholder…

The only requirement here is needing to run the Pro or Server edition of DEVONthink to use the custom metadata. For Standard users, there is the possibility of using the Finder Comments instead.

4 Likes

Sidebar: is there a glossary of Devonthink-specific terms/variables/instructions for AppleScript? I would not have known this.

1 Like

Just drop DEVONthink 3.app onto the Script Editor’s Dock/Finder icon to view its complete AppleScript suite.

Thank you! Can I suggest putting that action in the documentation somewhere?

A different approach is already part of the documentation, see page 200 of the PDF:

2 Likes

Welcome @CynthesisToday

You’d need to add your own custom metadata or else just use that Page attribute. That’s up to you.

It’s getting the information from the PDF itself.