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
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
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.
can you please help me a little with this? I have created a custom data field but when I do want to create the smart rule How do I enter the placeholder page count? If I command click on the empty filed there is no option to enter a placeholder
Interestingly, that seems to depend on the type of custom metadata. I can choose placeholders for âISBNâ and âReferenceâ which are both of type âsingle line textâ. OTOH, I donât get to choose placeholder for âamountâ, which is floating point number (all of these are predefined by DT, I think).
So, perhaps changing the field type to text helps? Or perhaps itâs not a workaround since you want to treat the custom metadata as number laterâŚ
Iâm not sure if this limitation of using placeholders only with certain metadata is intentional or a glitch. @cgrunenberg should know more about that.
If you need the page number in your custom meta data to be a real number (for example, if you want to sort records by number of pages or so), you could use a script in your smart rule. Something like
function performsmartrule(records) {
const app = Application("DEVONthink 3");
records.forEach(r =>
app.addCustomMetaData(r.pageCount(), {for: 'pagenumber', to: r})
)}
Usage: Select âExecute scriptâ, âJavaScriptâ as action in your smart rule and replace text in the âEdit scriptâ popup with this code. This assumes that your custom meta data is named âpagenumberâ. If not, change the word after the for in the r.addCustomMetadata() call.
Sorting is possible even ifâs a string, e.g. the names â1â, â2â and â10â are also sorted like numbers and not just like strings (in that case the order would be â1â, â10â, â2â)