Page 2 of 2

Re: Autolinking Bookends and DEVONthink records

Posted: Fri Apr 19, 2019 4:28 pm
by zvh
Jon can correct me if I'm wrong, but I'm not sure that there's yet a way to add attachments to existing records using AppleScipt. You might be able to cobble something together by using Finder's library to make the move, but it would likely be finicky and wouldn't, for instance, utilize your Bookends renaming preferences.

If I'm wrong and that function does exist, then I could probably script something rather easily.

Re: Autolinking Bookends and DEVONthink records

Posted: Sat Apr 20, 2019 9:40 am
by Jon
Yes, you can add attachments to existing records using AppleScript. Please check out Bookends' AppleScript dictionary, and see the documentation, or this link to our sites page on scripting Bookends, for more information.

https://www.sonnysoftware.com/scriptingbookends/

Jon
Sonny Software

Re: Autolinking Bookends and DEVONthink records

Posted: Sat Apr 20, 2019 11:48 am
by zvh
Thanks for clarifying, Jon. I've just looked through the manual and dictionary again and can't figure out how to add an attachment item to a currently existing publication item--at least in a way that will import and rename the file. I can easily add a new publication item, whether via quick add or as a record, and can do things with the attachments of current pub items, but could you point me to the part of the documentation where it specifies importing new attachments to existing references?

No worries if not. I know you're busy and this is more for tinkering than anything else. Not at all an urgent problem and, again, the problem is entirely on my end.

Re: Autolinking Bookends and DEVONthink records

Posted: Sat Apr 20, 2019 12:24 pm
by Jon
No problem. Fetch the names of the existing attachments (in the "attachments" field, append the new one (the names are separated with \n), then send the edited attachments field back to Bookends to replace the original.

Jon
Sonny Software

Re: Autolinking Bookends and DEVONthink records

Posted: Sat Apr 20, 2019 2:05 pm
by zvh
Thanks so much for your help!

This doesn't seem to import the actual file from its original path though, does it? (Or should it?) I can add to the attachments field, but this just returns "Can't find file" in Bookends, while the item in the attachment items list is incomplete. Here's part of what I've been experimenting with, for reference:

Code: Select all

tell application id "DNtp"
	set sel to the selection
	set thePath to path of item 1 of sel
	set theName to name of item 1 of sel
	set newItem to {path:thePath, name:theName, id:theName}
	tell application "Bookends"
		tell front library window
			set theRecord to publication items whose id is theQuery
			set theItem to item 1 of theRecord
			set theAttachments to attachments of theItem
			set theAttachments to theAttachments & linefeed & thePath
			# set theAttachments to theAttachments & linefeed & theName
			# add newItem to attachment items of publication item theRecord
			# set theAttachments to attachment items of item 1 of theRecord
			# add {path:thePath, name:theName, id:theName} to attachment items of item 1 of theRecord
			# copy newItem to end of theAttachments
		end tell
	end tell
end tell

Re: Autolinking Bookends and DEVONthink records

Posted: Sat Apr 20, 2019 3:38 pm
by Jon
It doesn't import anything at all. It just tells Bookends the reference is attached to the file with the name you added, and it will look in the default attachment folder for that file. As I wrote, actually getting the pDF into the default attachment folder is up to you.

Jon
Sonny Software

Re: Autolinking Bookends and DEVONthink records

Posted: Sat Apr 20, 2019 9:19 pm
by fmeres
As I understand it in order for the script to work then it should have DT export the pdf to the Bookends attachment folder and have Bookends add the file to the pre-existing (selected) reference, right?

Re: Autolinking Bookends and DEVONthink records

Posted: Sun Apr 21, 2019 7:56 am
by Jon
That is correct. By setting adding the PDF name to the Bookends database all you're telling Bookends to do is *look* in the default folder for the PDF of that name. Bookends won't move the file there.

Jon
Sonny Software

Re: Autolinking Bookends and DEVONthink records

Posted: Wed May 01, 2019 5:02 pm
by Dellu
Hi Zach,
I was trying to modify the script to change the creation date of the pdf file to the publication date.

Code: Select all

{theKey, thePath, theAuthor, theEditor, theTitle, theWords, theDate} to {citekey, path of attachment items, authors, editors, title, keywords, publication date string} of myItem

Code: Select all

do shell script "/usr/local/bin/exiftool -title=" & quoted form of theTitle & " -author=" & quoted form of theAuthor & "  -keywords=" & quoted form of theWords & " -fileCreateDate=" & quoted form of theDate & " -overwrite_original " & quoted form of thisPath

can you help me please?
I couldn't figure out why this cannot change the creation date.

Re: Autolinking Bookends and DEVONthink records

Posted: Wed May 01, 2019 6:09 pm
by Dellu
I found a way to do it now. The date formatting was the problem.

Adding the following line correctly imparted the creation date from date of the publication.

Code: Select all

set {theKey, thePath, theAuthor, theEditor, theTitle, theWords, theDate} to {citekey, path of attachment items, authors, editors, title, keywords, publication date string} of myItem

Code: Select all

set MyDay to (do shell script "date '+:%m:%d %H:%M:%S'")
		set MyDate to (theDate & MyDay)

Code: Select all

do shell script "/usr/local/bin/exiftool -title=" & quoted form of theTitle & " -author=" & quoted form of theAuthor & "  -keywords=" & quoted form of theWords & " -CreateDate=" & MyDate & " -overwrite_original " & quoted form of thisPath

Re: Autolinking Bookends and DEVONthink records

Posted: Thu May 02, 2019 12:37 pm
by zvh
Glad to see you figured that out, Dellu.

Also, sorry to be late on replying again to the previous query regarding exporting from DTPO to currently existing Bookends records. Adding the record to Bookends, then, is pretty simple. What you'd do to move the item is either get the path from DEVONthink and then tell Finder to move the file to your Bookends library, or else move the record within DEVONthink to your indexed Bookends folder (if you have one) and then deconsolidate the record to add it to the external folder. You could also rename it in either case by retrieving the reference info from Bookends that corresponds to your naming format and then telling DEVONthink to rename the item.

However, for me at least, this is more effort (and more breakable) than it's worth, given that you can just drag and drop from DEVONthink into Bookends. I agree that it would be nice to select a reference to import a file to without having to have both apps open side-by-side with the record selected--and this is doable--but I, at least, have my files renamed (and special characters removed) through Bookends. Doing this guarantees consistency. So, while this could mostly be hacked together without the aid of Bookends import, for me personally it's something best left to Bookends.

Re: Autolinking Bookends and DEVONthink records

Posted: Sat Jun 15, 2019 6:23 pm
by mk7
Hi, you'll have to excuse my ignorance here, but I've been trying to work this out and just can't swing it. I want to be able to use the script that works on selected items, but instead of creating a linked record in DT with the PDF, I want to create a blank note. I modified part of it so that it reads:

Code: Select all

set theRecord to create record with {type:markdown, name:theAuthor & " " & "-" & theTitle} in theLocation
Except for some reason that I can't figure out it still only works if there's a PDF attached to the reference. Is there any way to disable that? I tried removing these lines, but it didn't help:

Code: Select all

set thePath to path of attachment items of myItem
if thePath is not {} then
Also, you mentioned in the original post that you use the wikilink feature to associate your notes with the item in DT--would you mind explaining how that works? Where do you put your notes? Are they automatically created somehow? Thanks!

Re: Autolinking Bookends and DEVONthink records

Posted: Sun Jun 16, 2019 1:42 pm
by zvh
I think the section giving you problems now is

Code: Select all

repeat with i in thePath
or rather any remaining usage of the variable "thePath" insofar as you no longer create that variable when you remove this line:

Code: Select all

set thePath to path of attachment items of myItem
Those checks were created to make sure the script didn't try to process a reference without an attachment, so removing them should allow you to create items in DEVONthink rather than indexing pre-existing attachments.

As for the wikilink section of my comments, I was noting that DEVONthink will (if the option is turned on in preferences) automatically create links in your text notes to any item in that database whose alias is the same as the text in the note. So, for instance, if my BibKey for an item is "Smith2019" and I make this the alias of the reference I index in DEVONthink, then any time I want to link to this, all I have to do is put "Smith2019" in my note and it will link me to however many other files (notes or pdf) have that as an alias. How I actually create my notes is actually a bit too elaborate to write out at the moment--and also involves a couple of scripts that are a bit idiosyncratic. But I'll try to do so when I get some free time.

Hope this helps!

Re: Autolinking Bookends and DEVONthink records

Posted: Sun Jun 16, 2019 9:15 pm
by mk7
That did it! Thanks so much.

Trying to figure out the ideal writing/referencing workflow, so if you get a moment would love to hear how you swing it. Also trying to make this work on iOS, which is what I primarily work on. Thanks again.