Getting a specific reference format using JXA

Users asking other users for AppleScripts that work with Bookends.
Post Reply
pkus
Posts: 2
Joined: Tue Feb 28, 2023 5:48 am

Getting a specific reference format using JXA

Post by pkus »

Hi everyone,

I'm trying to integrate Bookends and DEVONthink using Javascript for Automation. I've managed to convert the item fields in BE to custom metadata in DT, but I'm struggling with getting a reference in a specific format, which I want to use for renaming the file in DT.

This little script does give me the default reference format, but I don't know how to specify a format within the `.format()` method. Unfortunately the details and examples in the Scripting Dictionary are all AppleScript-specific.

Code: Select all

const bookends = Application("Bookends");
const devonthink = Application("DEVONthink 3");
devonthink.includeStandardAdditions = true;

let items = bookends.libraryWindows[0].selectedPublicationItems();
let item = items[0];
let shortRef = item.format();

console.log(`${shortRef}`);
Jon
Site Admin
Posts: 10048
Joined: Tue Jul 13, 2004 6:27 pm
Location: Bethesda, MD
Contact:

Re: Getting a specific reference format using JXA

Post by Jon »

I don't have any specific knowledge of how to use JS here, hopefully someone else does. But have you tried the format name? -- let shortRef = item.format('Nature.fmt'); (or maybe "Nature.fmt")?

Jon
Sonny Software
pkus
Posts: 2
Joined: Tue Feb 28, 2023 5:48 am

Re: Getting a specific reference format using JXA

Post by pkus »

Thanks for the reply.

I had tried `item.format('Nature.fmt')` already, that does not work. But after some trial and error I've found the solution:

Code: Select all

let shortRef = item.format({using: 'Nature.fmt'});
ComplexPoint
Posts: 9
Joined: Sun Jun 26, 2016 7:19 pm

Re: Getting a specific reference format using JXA

Post by ComplexPoint »

The trick is to load the scripting library in Script Editor:

Code: Select all

File > Open Dictionary... > Bookends
and change the language selector at the top from AppleScript to JavaScript.

Searching for

Code: Select all

format
you will then see:

Code: Select all

format PublicationItem or list of PublicationItem : The publication item(s) that will be formatted.

[using: text] : The reference format to use. If no format name is supplied, the default format specified in Bookends will be used. May be any format name supported by the Bookends Formats Manager, including tagged formats such as 'BibTeX', 'EndNote XML' or 'RIS'.

[as: "plain text"/‌"RTF"/‌"BibTeX"/‌"HTML"] : The file format to use. Defaults to 'plain text'.
→ text : The formatted reference(s). If multiple publication items are given, the returned references will be separated by a Return character.
Values for additional argument keywords like

Code: Select all

using:
and

Code: Select all

as:
are always supplied in the form of a JS "Object" i.e. a

Code: Select all

{key:value, keyN:valueN}
dictionary.
Post Reply