Skip to content

Instantly share code, notes, and snippets.

@neilernst
Created September 4, 2010 19:34
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save neilernst/565427 to your computer and use it in GitHub Desktop.
Save neilernst/565427 to your computer and use it in GitHub Desktop.
Find citation keys using Mendeley
#!/usr/bin/ruby
require 'sqlite3'
cite_part = ARGV[0]
db_name = "/Users/nernst/Library/Application\ Support/Mendeley\ Desktop/neil\@neilernst.net\@www.mendeley.com.sqlite"
db = SQLite3::Database.new( db_name )
db.results_as_hash = true
query = "select citationkey, title, year from Documents where citationkey like '%#{cite_part}%'"#MATCH '#{cite_part}'"#{}like '%#{cite_part}%'"
db.execute( query ) do |row|
print row['citationKey'] + '|'
#print '@row:' + row['citationKey'] + "|" + row['title'] + "|" + row['year'].to_s
end
on run {input, parameters}
set cite to input --"" --"jureta"
set delimitedList to {}
-- set test to "Carvalho2005a|Hayes2008|Sampaio2005|Sawyer2002|Searle1976|Baker|Denecker2002|Liu2009|Anbulagan2009"
set ssresult to do shell script "/Users/nernst/Desktop/query_cite.rb " & cite as string
set tid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "|"
set delimitedList to every text item of ssresult
set y to choose from list delimitedList
set AppleScript's text item delimiters to tid
return y
end run
@neilernst
Copy link
Author

A ruby and apple script to run sqlite against Mendeley databases. Warning: I wouldn't recommend changing the DB unless you want to mess up the client.

Currently this script does not allow one to see the paper title, which would be good for disambiguation. It was enough work getting lists to display in Applescript.

Getting it to work:

  • change the pathnames to your database.
  • might need to install Sqlite gem for ruby (could probably just use a bash script to do this and command line sqlite)
  • create an automator service (attached)
  • higlight a cite key in your document (e.g. scrivener) and find the service menu. Select from list and content is in the clipboard.
  • might be good to add a hotkey via the Keyboard preference pane.

@bjordan555
Copy link

Really useful snippet of code Neil. I've used it to automate some bibliographies, and inserted it into my university's thesis template.

I'm now trying to do some queries of the full text part of the database that Mendeley keeps. Have you been successful with that, or heard of anyone doing it? I don't see the fields that link to the file indexes that the full text is stored in, but I've only started trying to reverse engineer that part.

Thanks,

Ben

@neilernst
Copy link
Author

No, I haven't. I would recommend posting on the Mendeley website and forums about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment