Auto-generating journal abbreviations

Zotero's existing journal abbreviation generators weren't meeting my needs, so I put together a script that can be run in the "run JavaScript" terminal from Tools->Developer-> Run Javascript.

I thought I would share it here in case it is helpful to anyone else. The journals are astronomy heavy, but editing them for your own needs is as simple as changing the array names at the start of the script to match your target journal and desired abbreviation.

Note: I am not a JavaScript programmer, so I apologise if the below code is an eyesore.

jAbbr = "journalAbbreviation";
const ApJ = new Array("The Astrophysical Journal",'ApJ');
const ApJL = new Array("The Astrophysical Journal Letters",'ApJL');
const ApJS = new Array("The Astrophysical Journal Supplement Series","ApJS");
const MNRAS = new Array("Monthly Notices of the Royal Astronomical Society","MNRAS");
const AJ = new Array("The Astronomical Journal", "AJ");
const AA = new Array("Astronomy and Astrophysics","A&A");
const PASA = new Array("Publications of the Astronomical Society of Australia","PASA");
const PASP = new Array("Publications of the Astronomical Society of the Pacific","PASP");
const ARAA = new Array("Annual Review of Astronomy and Astrophysics","ARAA");
const AstL = new Array("Astronomy Letters","AstL");
const ApSS = new Array("Astronomy and Space Science","Ap&SS");
const Nat = new Array("Nature","Nature");
const NewA = new Array("New Astronomy","NewA");
const NewAR = new Array("New Astronomy Reviews","NewAR");
const NuPhA = new Array("Nuclear Physics A", "NuPhA");
const PhR = new Array("Physics Reports","PhR");
const PNAS = new Array("Proceedings of the National Academy of Science","PNAS");
const RvMP = new Array("Reviews of Modern Physics","RvMP");
const AAR = new Array("The Astronomy and Astrophysics Review","A&AR");

var s = new Zotero.Search();
s.libraryID = ZoteroPane.getSelectedLibraryID();
var ids = await s.search();
if (!ids.length) {
return "No items found";
}
await Zotero.DB.executeTransaction(async function () {
for (let id of ids) {
let item = await Zotero.Items.getAsync(id);
let pubFieldID = item.getField("publicationTitle");
let AbbrFieldID = item.getField(jAbbr);

if (pubFieldID == ApJ[0]) {
item.setField(jAbbr, ApJ[1]);
}
if (pubFieldID == ApJL[0]) {
item.setField(jAbbr, ApJL[1]);
}
if (pubFieldID == ApJS[0]) {
item.setField(jAbbr, ApJS[1]);
}
if (pubFieldID == MNRAS[0]) {
item.setField(jAbbr, MNRAS[1]);
}
if (pubFieldID == AJ[0]) {
item.setField(jAbbr, AJ[1]);
}
if (pubFieldID == AA[0]) {
item.setField(jAbbr, AA[1]);
}
if (pubFieldID == PASA[0]) {
item.setField(jAbbr, PASA[1]);
}
if (pubFieldID == PASP[0]) {
item.setField(jAbbr, PASP[1]);
}
if (pubFieldID == ARAA[0]) {
item.setField(jAbbr, ARAA[1]);
}
if (pubFieldID == AstL[0]) {
item.setField(jAbbr, AstL[1]);
}
if (pubFieldID == ApSS[0]) {
item.setField(jAbbr, ApSS[1]);
}
if (pubFieldID == Nat[0]) {
item.setField(jAbbr, Nat[1]);
}
if (pubFieldID == NewA[0]) {
item.setField(jAbbr, NewA[1]);
}
if (pubFieldID == NewAR[0]) {
item.setField(jAbbr, NewAR[1]);
}
if (pubFieldID == NuPhA[0]) {
item.setField(jAbbr, NuPhA[1]);
}
if (pubFieldID == PhR[0]) {
item.setField(jAbbr, PhR[1]);
}
if (pubFieldID == PNAS[0]) {
item.setField(jAbbr, PNAS[1]);
}
if (pubFieldID == RvMP[0]) {
item.setField(jAbbr, RvMP[1]);
}
if (pubFieldID == AAR[0]) {
item.setField(jAbbr, AAR[1]);
}
await item.save();
}
});
return ids.length + " item(s) updated";
Sign In or Register to comment.