Skip to content

Instantly share code, notes, and snippets.

@gawbul
Forked from neilernst/query_cite.rb
Created July 4, 2011 18:35
Show Gist options
  • Save gawbul/1063753 to your computer and use it in GitHub Desktop.
Save gawbul/1063753 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment