Permalink
Browse files

Updates to:

Papers → Copy to BibDesk
TeXShop → Find in Papers
TeXShop → Find Undefined Citation
  • Loading branch information...
1 parent b06c79d commit 35a2e553a012a5121cfae61ace636b9aba47a672 @bjmorgan committed Mar 27, 2012
Showing with 62 additions and 9 deletions.
  1. +11 −2 Papers 2.2.5/Copy to BibDesk
  2. +11 −7 TeXShop/Find Undefined Citations
  3. +40 −0 TeXShop/Find in Papers
@@ -11,7 +11,13 @@ def records # still hoping that Papers2 will become AppleScriptable
clipboard = OSAX.osax.the_clipboard
return clipboard[0] == "%" ? clipboard.split("\r\r")[1..-1] : [ clipboard ]
end
-
+
+class String
+ def parse_author_initials!
+ replace( self.split("\r").map { |line| /author/.match(line) ? line.gsub(/([A-Z])([ }])/, "\\1.\\2") : line }.join("\r") )
+ end
+end
+
$papers = Appscript.app("/Applications/Papers2.app")
bibdesk = Appscript.app("/Applications/BibDesk.app")
@@ -21,5 +27,8 @@ library = "/Users/ben/Documents/My Papers/Bibliography.bib"
bibdesk.run unless bibdesk.is_running?
bibdesk.open(MacTypes::Alias.path( library ) ) unless bibdesk.documents.count > 0
-records.each{ |article| bibdesk.documents[1].import( :from => article ) }
+records.each do |article|
+ article.parse_author_initials!
+ bibdesk.documents[1].import( :from => article )
+end
bibdesk.activate
@@ -16,11 +16,15 @@ filepath = MacTypes::Alias.path( file )
logfile = File.new( file, "r" ).readlines
cite_warning = /Citation `([A-Za-z]+_[A-Za-z]+[0-9]+[a-z]*)'/
cites_not_found = logfile.collect{ |line| cite_warning.match( line )[1] unless cite_warning.match( line ).nil? }.compact
-selection = osax.choose_from_list( cites_not_found, :with_prompt => "Undefined Citations:" )
-if selection then
- osax.set_the_clipboard_to( selection[0] )
- texshop.activate
- sys_events.keystroke('f', :using => :command_down )
- sys_events.keystroke('v', :using => :command_down )
- sys_events.keystroke("\r")
+if cites_not_found.empty? then
+ osax.display_dialog( "No undefined citations.", :buttons => ["OK"] )
+else
+ selection = osax.choose_from_list( cites_not_found, :with_prompt => "#{cites_not_found.length} undefined Citations:" )
+ if selection then
+ osax.set_the_clipboard_to( selection[0] )
+ texshop.activate
+ sys_events.keystroke('f', :using => :command_down )
+ sys_events.keystroke('v', :using => :command_down )
+ sys_events.keystroke("\r")
+ end
end
@@ -0,0 +1,40 @@
+#!/usr/local/bin/ruby
+
+# March 14, 2012
+
+require 'appscript'
+require 'osax'
+
+class String
+ def is_citation?
+ cite_re = /[A-Za-z]+_[A-Za-z]+[0-9]+[a-z]*/
+ return cite_re.match(self) ? true : false
+ end
+end
+
+def new_bibitem( cite_key )
+ return "@article{#{cite_key},
+author = {}
+}"
+end
+
+osax = OSAX.osax
+texshop = Appscript.app("TeXShop")
+sys_events = Appscript.app("System Events")
+bibdesk = Appscript.app("BibDesk")
+papers = Appscript.app("Papers2")
+whose = Appscript.its
+library = "/Users/ben/Documents/My Papers/Bibliography.bib"
+
+texshop.activate
+cite_key = texshop.document.selection.content.get[0]
+unless cite_key.is_citation? then
+ osax.display_alert("'#{cite_key}' is not a valid cite key", :buttons => ["Cancel"])
+ exit(0)
+end
+
+papers.activate
+osax.set_the_clipboard_to( cite_key )
+sys_events.keystroke('l', :using => :command_down ) # switch to full library
+sys_events.keystroke('f', :using => :command_down ) # focus on seach bar
+sys_events.keystroke('v', :using => :command_down ) # paste cite_key into search bar

0 comments on commit 35a2e55

Please sign in to comment.