How to make imprint to PDF with custom metadata via AppleScript?

My PDF-file has custom metadata. Imprint via GUI works OK — it inserts custom metadata as placeholders.

How can I make imprint to PDF with custom metadata via AppleScript?

Please help to add custom metadata to my script

tell application id "DNtp"
	
	set theSelection to the selection
	
	if (count of theSelection) is 1 then
		set theRecord to the content record
		imprint font "Times New Roman Italic" position top center record theRecord size 15 text "Some text"
	end if
	
end tell

Welcome @Igor_B

Have you set up an imprint configuration in Preferences > Imprinter ?
If not, I suggest you start there.

Once you’ve established an imprint configuration, you could hard code it into a script or as an alternative, allow choosing an imprint to apply. Here’s a simple example of the latter…

tell application id "DNtp"
	repeat with thisFile in (selection as list)
		set recordType to (type of thisFile as string)
		if (recordType = "PDF document") or (recordType = "image") then
			set imprinterList to (get imprinter configuration names)
			set chosenImprint to choose from list imprinterList
			imprint configuration (item 1 of chosenImprint) to thisFile
		end if
	end repeat
end tell

PS: I suggest you enable Duplicate item before imprinting in Preferences > Imprinter, at least while you’re testing. This will preserve the original file and imprint a copy.

Jim, how to avoid using GUI configuration at all?

I use Keyboard Maestro with synchronization between macs. So I make changes at one mac only, and get them at another one.

There are several complicated imprints, and they work well via GUI. But it is tedious to sync them between macs. Especially after reinstall macOS.

How to imprint custom metadata via script only?

Is there way to

  • synk imprint configuration between macs or
  • read custom metadata with Applescript — this would allow to sync Applescripts between macs and use the same imprint configurations

?

You could try to use

/Users/Username/Library/Application Support/DEVONthink 3/imprinter.data

for syncing. Note: I don’t know if this can cause damage.

What do you need via AppleScript?

Don’t understand what you have in mind, please elaborate.

No there is currently no way from DEVONthink to sync the imprinter settings. You could manually transfer it but DEVONthink on the receiving machine should be closed before replacing the file.

AppleScript for what?

set md to custom meta data of theRecord
set myVariable to myMDIdent of md

where myMDIdent is the Identifier of the custom meta data as set in the DT Preferences, and theRecord points to the record in question.

Dear All, thanks for your replies. All the answers helped me to choose method (I choose Applescript + Keyboard Maestro), and to make my Applescript.

We used to use different complicated imprints via Graphic User Interface for our sells and shippings. Everything works OK. The only problem was to synchronize imprint configurations between macs.

Also we use Keyboard Maestro, which make synchronization for macros between our macs.

Now I made my macros with Applescript, and macros are synchronized!

Here is example of Applescript for Keyboard Maestro

tell application id "DNtp"

	set theSelection to the selection
	
	if (count of theSelection) is 1 then
		
		set theRecord to the content record
		set recordType to (type of theRecord as string)
		
		if (recordType = "PDF document") then
			
			set recordCarrier to get custom meta data for "carrier" from theRecord
			
			set myText to "Carrier: " & recordCarrier
			
			imprint font "Times New Roman Italic" position top center record theRecord size 15 text myText -- Add here some formatting
						
			return myText
			
		else
			return "Select PDF file"
		end if
		
	else
		return "Select one PDF file"
	end if
	
end tell

DEVONthink + Keyboard Maestro = Even More Power

Thanks again!

2 Likes