Is adding attachments to publication items possible via scripting?

Users asking other users for AppleScripts that work with Bookends.
Post Reply
ryanjamurphy
Posts: 20
Joined: Mon May 20, 2019 8:41 pm

Is adding attachments to publication items possible via scripting?

Post by ryanjamurphy »

Hiya. I'm trying to make sure that every file added to a particular DEVONthink group becomes a Bookends publication item.

Creating a publication item is easy:

Code: Select all

set newPublication to make new publication item with properties {name: "Some name"}
However, I can't figure out how to add an attachment to the newly-created item in Bookends. I imagine something like the below should work, but it doesn't seem like "make new attachment item" is a thing. Specifically I get the error "Can’t make or move that element into that container." with the following line and a variety of similar attempts:

Code: Select all

set newAttachmentItem to make new attachment item with properties {path:recordPath}
Here's the full (draft) script:

Code: Select all

on addRecordToBookends(someRecord)
	tell application id "DNtp"
		set recordNameWithoutExtension to someRecord's name without extension
		set recordName to someRecord's name
		set recordPath to someRecord's path
		tell application "Bookends"
			tell front library window
				set newPublicationItem to make new publication item with properties {title:recordNameWithoutExtension as text}
				set newAttachmentItem to make new attachment item with properties {name: someName, path:recordPath}
				set newPublicationItem's attachments to newAttachmentItem
			end tell
		end tell
	end tell
end addRecordToBookends
Any ideas? Or is there something else I can try? Thanks!
Jon
Site Admin
Posts: 10048
Joined: Tue Jul 13, 2004 6:27 pm
Location: Bethesda, MD
Contact:

Re: Is adding attachments to publication items possible via scripting?

Post by Jon »

Attachments are stored in the attachment field by file name (not path) in a \n-delimited list. So for a new publication simply insert the PDF name into that field.

Jon
Sonny Software
ryanjamurphy
Posts: 20
Joined: Mon May 20, 2019 8:41 pm

Re: Is adding attachments to publication items possible via scripting?

Post by ryanjamurphy »

Great, thanks, Jon!
Jon
Site Admin
Posts: 10048
Joined: Tue Jul 13, 2004 6:27 pm
Location: Bethesda, MD
Contact:

Re: Is adding attachments to publication items possible via scripting?

Post by Jon »

I should have added that since you're bypassing the check that Bookends does to make sure the name is unique, it's your responsibility to be sure it is. If there is another file with the same name in an attachment subfolder or ad hoc folder, Bookends may find the wrong one when you select the reference.

Jon
Sonny Software
Post Reply