Papers to Bookends export script

Users asking other users for AppleScripts that work with Bookends.
msteffens
Posts: 33
Joined: Thu Jul 19, 2007 10:04 am
Location: Germany
Contact:

Papers to Bookends export script

Post by msteffens »

Hi everyone,

I've written a "Papers to Bookends" script which exports all publications selected in your Papers 3 library to Bookends:

https://github.com/extracts/mac-scripti ... o_Bookends

The script will also transfer the publication's primary PDF (if there's any) and can also transfer the publication's rating, color label, flagged status, language, edition, citekey, and "papers://..." link.

The PDF file's annotations can be also transferred if you follow the steps given in the "Known Issues" section of the README.

Hope this is useful to somebody.
Cheers, Matthias

Thompson
Posts: 7
Joined: Thu Oct 12, 2017 4:35 am

Re: Papers to Bookends export script

Post by Thompson »

Thank you for the script Matthias!

I have a bit problem of using it. When try to run the script I get error:

unable to set argument 2 - the AppleScript value <NSAppleEventDescriptor: { 'usrf':[ 'utxt'("location"), 9.22337e+18, 'utxt'("length"), 0 ] }> could not be coerced to type {_NSRange=QQ}.

unable to set argument 2 - the AppleScript value <NSAppleEventDescriptor: { 'usrf':[ 'utxt'("location"), 9.22337e+18, 'utxt'("length"), 0 ] }> could not be coerced to type {_NSRange=QQ}. (-10000)

Result is that only one citation gets exported from papers. Do you have idea what is the problem? I'm not expert in scripting so it's difficult to understand.

Juha

msteffens
Posts: 33
Joined: Thu Jul 19, 2007 10:04 am
Location: Germany
Contact:

Re: Papers to Bookends export script

Post by msteffens »

Hi Juha,

sorry to hear you're facing trouble!

It's hard to say where exactly the script fails, but I think that the issue depends on the particular records you've selected in your Papers library. In other words, does this issue also happen if you select some different records in your Papers library?

If you've found some records in your Papers library for which this issue always happens, it would be great if you could choose "File > Export… > Papers Archive" for these records, and then upload the resulting Papers archive file as an attachment here (or send it to mat (at) extracts (dot) de. This will hopefully allow me to reproduce the issue.

Thanks!
Matthias

Thompson
Posts: 7
Joined: Thu Oct 12, 2017 4:35 am

Re: Papers to Bookends export script

Post by Thompson »

Hello Matthias,

Thank you for your reply. This error happens in on any paper I try to run the script (or executable) on. Even if I select only one paper this error message appears, but the result is always the same that one paper (the first one that is highlighted) gets added to Bookends library. Everything is correct on that imported paper.

I'm wondering if this issue has something to do with high sierra update (possibly new file system) which has been causing so many troubles recently. Also if it has some relevance, I get error message "An error has occurred: database engine error: -47" when trying to create new Bookends library. This would point that the problem could be also in side of Bookends.

-Juha

msteffens
Posts: 33
Joined: Thu Jul 19, 2007 10:04 am
Location: Germany
Contact:

Re: Papers to Bookends export script

Post by msteffens »

Hi Juha,

thanks for the additional info! Since the error is about a range that can't be created, I _think_ that the issue lies with the script, esp. with one of the methods which use a regex pattern.

Thus it would still be helpful if you could select a few of your records in your Papers library, export them as a Papers Archive, and send them to me, as suggested in my last email:
it would be great if you could choose "File > Export… > Papers Archive" for these records, and then upload the resulting Papers archive file as an attachment here (or send it to mat (at) extracts (dot) de.
Also, could you tell us which exact version numbers of Bookends and Papers you're using?

Many thanks!
Matthias

Jon
Site Admin
Posts: 8664
Joined: Tue Jul 13, 2004 6:27 pm
Location: Bethesda, MD
Contact:

Re: Papers to Bookends export script

Post by Jon »

The -47 error means the file is in use (busy). Another user with this problem was using anti-virus software and that was the problem. If you are, too, either turn if off or whitelist Bookends.

Jon
Sonny Software

Thompson
Posts: 7
Joined: Thu Oct 12, 2017 4:35 am

Re: Papers to Bookends export script

Post by Thompson »

Thanks Jon, that fixed the library error. I still can not get the script working though. Matthias, I have sent some documents to your email as you requested.

-Juha

msteffens
Posts: 33
Joined: Thu Jul 19, 2007 10:04 am
Location: Germany
Contact:

Re: Papers to Bookends export script

Post by msteffens »

Hi Juha,
Thompson wrote:I still can not get the script working though. Matthias, I have sent some documents to your email as you requested.
Thanks, I've received your sample records via email, that's very helpful!

With two of your three sample records (Perrin:2012vn & Dunford:2013cd) I also get a -10000 error when trying to export these publications to Bookends. It seems that Papers has trouble generating proper JSON output for these publications when the script asks for their `json string` property.

I've uploaded a new script version (v1.2) which attempts to work around this issue:

https://github.com/extracts/mac-scripti ... o_Bookends

Hope this helps. Let me know if this doesn't fix your issue.

Best, Matthias

Thompson
Posts: 7
Joined: Thu Oct 12, 2017 4:35 am

Re: Papers to Bookends export script

Post by Thompson »

Thank you for the effort, but I still get the same error with any document I try to export. I tried repairing my library, and also creating a new library, but both option resulted the same problem. It would be interesting to see if this is specifically problem of my library, or does other users experience the same problem.

Jon
Site Admin
Posts: 8664
Joined: Tue Jul 13, 2004 6:27 pm
Location: Bethesda, MD
Contact:

Re: Papers to Bookends export script

Post by Jon »

@Thompson The problem is with Papers, not Bookends, so if you are rebuilding the Bookends library, that's not going to help.

Jon
Sonny Software

msteffens
Posts: 33
Joined: Thu Jul 19, 2007 10:04 am
Location: Germany
Contact:

Re: Papers to Bookends export script

Post by msteffens »

Hi Juha,
Thompson wrote:Thank you for the effort, but I still get the same error with any document I try to export.
Sorry to hear that. So it seems that there's more issues involved. The error that I was receiving was also different compared to yours. I got this error (on a German system):

Code: Select all

„Papers“ hat einen Fehler erhalten: Fehler in der AppleEvent-Routine. (-10000)
I.e., Papers received an error in an AppleEvent routine (AppleEvent handler failed). However, your error message indicates an issue with one of the regex handlers in the used scripting library (which make use of AppleScriptObjC and NSRange ranges). Since I received the same error number, I naively hoped that my fix would also address your issue.

For me, running Papers 3.4.10 and Bookends 12.8.4 on macOS 10.11.6 (El Capitan), the script v1.2 now also works with your sample records.

If nothing else helps, and if you don't mind the extra effort, maybe you could open the script in a trial version of Script Debugger (http://latenightsw.com/free-trial/), and step thru the script in Debug mode and see were it fails. I.e., in Script Debugger, hit Cmd-Shift-D, then repeatedly hit Cmd-I until it fails. But I'll also continue trying to find the cause for your issue.

Thanks, Matthias

Thompson
Posts: 7
Joined: Thu Oct 12, 2017 4:35 am

Re: Papers to Bookends export script

Post by Thompson »

Hello,

I tried the Script Debugger, and did the procedure you described, and result is that it gives failure in line 278:

set language to KeypointsLib's regexMatch(pubJSON, "(?<=" & linefeed & " \"language\": \").+(?=\")")

Error message is identical what I get when running the script.

Does this help?
-Juha

msteffens
Posts: 33
Joined: Thu Jul 19, 2007 10:04 am
Location: Germany
Contact:

Re: Papers to Bookends export script

Post by msteffens »

Hi Juha,
Thompson wrote:I tried the Script Debugger, and did the procedure you described, and result is that it gives failure in line 278:

set language to KeypointsLib's regexMatch(pubJSON, "(?<=" & linefeed & " \"language\": \").+(?=\")")

Error message is identical what I get when running the script.
Does this help?
Many thanks for running the script in Script Debugger's debug mode, this greatly helped me to understand the issue! The issue is actually due to an AppleScriptObjC bug in macOS 10.13.0 (High Sierra). So, as you suspected initially, it indeed only happens on High Sierra.

I've uploaded a new script version (v1.3) which should work around this High Sierra issue. Here's a direct download link to the zipped script application:

https://github.com/extracts/mac-scripti ... ds.app.zip

Thanks for all the help and for your patience!
Matthias

Thompson
Posts: 7
Joined: Thu Oct 12, 2017 4:35 am

Re: Papers to Bookends export script

Post by Thompson »

Hello Matthias,

Yes it works now! Thanks so much for your help on this. If you are interested to develop the script further, one feature that would be useful to have is the exportation of Papers 3 annotations to the Bookends. I have feeling that this is not very easy to accomplish because Papers 3 has proprietary PDF reader, which doesn't translate well to other programs.

-Juha

msteffens
Posts: 33
Joined: Thu Jul 19, 2007 10:04 am
Location: Germany
Contact:

Re: Papers to Bookends export script

Post by msteffens »

Hi Juha,
Thompson wrote:Yes it works now! Thanks so much for your help on this.
That's great to hear!
Thompson wrote:one feature that would be useful to have is the exportation of Papers 3 annotations to the Bookends.
If you follow the steps given in the script's ReadMe, the script should already be able to transfer the annotations from Papers to Bookends.

The latest versions of Papers 3 have a scripting bug which prevents the scripted export of PDFs that include annotations. Thus it's necessary to manually export all PDFs (with annotations included) to the Bookends attachments folder. The script will then look for these PDFs and pass them to Bookends which will then also import their annotations.
Thompson wrote:I have feeling that this is not very easy to accomplish because Papers 3 has proprietary PDF reader, which doesn't translate well to other programs.
Papers 3 is fairly scriptable and also offers access to individual annotations via its scripting interface. So IMO this actually offers more flexibility than just having annotations baked into the PDF (which Papers also offers on export) since you can create all kinds of export workflows for your annotations. Here's some examples (which I hope to also move to the above-linked "mac-scripting" repo):
Matthias
Last edited by msteffens on Fri Dec 21, 2018 5:57 am, edited 1 time in total.

Post Reply