Script to export static/smart groups or folders matching a pattern to separate BibTeX files

Users asking other users for AppleScripts that work with Bookends.
Post Reply
naupaka
Posts: 5
Joined: Fri Mar 17, 2017 7:39 pm

Script to export static/smart groups or folders matching a pattern to separate BibTeX files

Post by naupaka »

Reposting from this thread: viewtopic.php?f=2&t=4105&p=19168#p19158

I've put together an applescript to export a particular group or folder of groups from Bookends to separate BibTeX files (one per group). It's meant to be run from the command line, with parameters that allow you to select which group(s)/folder(s) you'd like to export as well as where you would like the exported .bib files to go (see comments at the top of the file for more details and syntax).

The idea is that it could be used as part of a makefile or other build script for a paper you're writing in TeX or markdown. If you wanted to, you could set it to be run from a cron job or via something like Hazel if you wanted automated refreshing of export for a particular group or folder of groups. I wouldn't recommend using it to constantly re-export your entire database, since as Jon said, that takes a while and is probably not usually necessary.

Just as a test, I have tried to use this script to export a group with all of the references in my library (~6500 references), and it reliably crashes. It does seem to work pretty well on groups of references up to about 2000 items.

The script is available here: https://gist.github.com/naupaka/3637da8 ... 3575a7c2e1

iandol
Posts: 336
Joined: Fri Jan 25, 2008 2:31 pm

Re: Script to export static/smart groups or folders matching a pattern to separate BibTeX files

Post by iandol »

I noticed a bug. If the bib file already exists, it is not overwritten (applescript's "open for access" does not wipe a file when writing apparently), therefore if the new content is smaller than the previous, you end up with residual broken content from the previous file. So you need to delete the file first if it exists before opening it:

Code: Select all

set thisFile to (myPath & (myGroup as string) & ".bib") as POSIX file
set quotedName to quoted form of POSIX path of thisFile
tell application "Finder"
	if exists thisFile then
		delete thisFile
	end if
end tell
set myFile to open for access thisFile with write permission
Fixed in my fork:
https://gist.github.com/iandol/90684eee ... -scpt-L150

Applescript is **such a pain**!!!

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

Re: Script to export static/smart groups or folders matching a pattern to separate BibTeX files

Post by Jon »

The option to output acronyms in brackets, e.g. {DNA}, is available in Bookends preferences (BibTeX tab). Did that not work for you?

Jon
Sonny Software

Post Reply