On Jan 25, 2014, at 15:59, Ken Mankoff wrote:

> Ok all done! Thanks for those who supplied some tips. With this AppleScript 
> and a working pdfmeat.py (test it from the command line), I can drag a PDF 
> into BibDesk, select it, and populate it with all of the data from Google 
> Scholar.
> 
>   -k.
> 
> property useFileURL : true
> 
> -- use relative or absolute path?
> 
> property useRelativePath : false
> 
> -- delete linked files/URLs after converting?
> 
> property deleteLinkedFiles : false
> 
> 
> 
> tell application "BibDesk"
> 
> set theDoc to document 1
> 
> tell theDoc
> 
> set theSel to selection
> 
> set thePub to item 1 of theSel
> 
> tell thePub
> 
> -- current (probably empty?) BibTeX record
> 
> set curBibTeXRecord to get BibTeX string of thePub
> 
> 
> -- get the BibTeX record using pdfmeat.py. Wrap it in a shell script because 
> it needs a full path, write access to a folder, etc.
> 
> set theFile to get linked files
> 

This is really an array, so this can go wrong. You can use linked file 1.
> set thePath to POSIX path of theFile
> 
> set shellOpts to "cd /tmp; PATH=$PATH:/usr/local/bin " -- path to pdftotext 
> program
> 
> set pdfMeatCmd to "/path/to/python /path/to/pdfmeat.py  "
> 
> set shellCmd to shellOpts & pdfMeatCmd & "'" & thePath & "'"
> 

Applescript has the standard command "quoted form of" to get the quotes.

> set pdfMeatOutput to do shell script shellCmd
> 
> end tell
> 
> 
> set newPubs to import from pdfMeatOutput
> 
> set newPub to (get item 1 of newPubs)
> 
> tell newPub
> 
> make new linked file with data theFile at beginning of linked files
> 
> 
You can also do:

add (linked files of thePub) to linked files
> set cite key to generated cite key
> 
> end tell
> 
> 
> show thePub
> 
> show newPub
> 
> --delete thePub
> 
> end tell
> 
> end tell
> 


As I said, you can also copy the fields from newPub to thePub. This may be 
better if you need some more control, for instance if thePub may already have 
some fields set. Something like:

set ignoredFields to {"Date-Added", "Date-Modified"}
repeat with theField in fields of newPub
set theName to name of theField
if theName is not in ignoredFields and value of field theName of thePub is "" 
then
set value of field thePub to value of theField
end if
end repeat

Christiaan

------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
Bibdesk-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-users

Reply via email to