Automate case protection enabling/disabling
Hello
I have asked a question on tex Stack Exchange about how one could change multiple entries' sentence case/title case at once but we have not reached a solution. My current practice is to click each title field and select Sentence case of Title Case. Please see if you could help me out.
https://tex.stackexchange.com/questions/546976/is-there-a-command-to-make-reference-entries-type-consistent/548122?noredirect=1#comment1388897_548122
I have asked a question on tex Stack Exchange about how one could change multiple entries' sentence case/title case at once but we have not reached a solution. My current practice is to click each title field and select Sentence case of Title Case. Please see if you could help me out.
https://tex.stackexchange.com/questions/546976/is-there-a-command-to-make-reference-entries-type-consistent/548122?noredirect=1#comment1388897_548122
(For what it's worth, I've wondered before whether it would make sense to bring an auto-conversion feature like we have in ZoteroBib to Zotero, but it'd be a bit more dangerous without the kind of explicit review step we have in ZoteroBib. Data can also get into a Zotero library in so many ways that it might get confusing. For example, we'd want it for saving from the web or Add Item by Identifier, but I'm not sure we'd want it to apply to imports from a file, but if you click a RIS file in the browser and the connector intercepts it, does that count as saving from the browser or as an import? Joining a group library obviously doesn't convert the items in that library, but if you drag an item from a group library to your own library, does it get converted? Also worth noting that in ZoteroBib it's only a soft conversion — if you change back to another style, it goes back to its original form, unless you made a manual edit in the meantime.)
const sentenceCase = Zotero.Utilities.sentenceCase || function (val) {
newVal = val.toLowerCase().replace(/\s*:/, ":");
newVal = newVal.replace(/(([\?!]\s*|^)([\'\"¡¿“‘„«\s]+)?[^\s])/g, function (x) {
return x.replace(/\s+/m, " ").toUpperCase();});
return newVal
}
let title
for (const item of Zotero.getActiveZoteroPane().getSelectedItems()) {
if (item.isFeedItem || !item.isRegularItem() || !(title = item.getField('title'))) continue
item.setField('title', sentenceCase(title))
await item.saveTx()
}
@emilianoeheyns Very handy, thank you.