1

Some Background: I've used Skim with BibDesk for a while now for reading and annotating scientific journal articles. Recently, I purchased an android tablet and would like to use it to read and annotate .pdfs as well. I use the reference library Eratosthenes with ezPDF Reader and sync all files through Dropbox. The issue I'm having is that Skim stores annotations as extended attribute files by default, which are not accessible to other devices through Dropbox. I've worked around this problem by saving the annotations as .fdf files and then linking the .fdf files to the citation entry in BibDesk. ezPDF reader can import .fdf files as annotations, and if the annotation file is linked to the BibDesk entry, both the .pdf and .fdf can be easily downloaded to the tablet without needing to sync the entire Dropbox folder full of hundreds of references.

I'd like to write an applescript that does this automatically, but am very new to applescript and am having a hard time getting started. I've written the following script to be executed when "command-s" is pressed while in skim:

tell application "Skim"
    set docPath to path of front document
    set notesPath to text 1 thru -5 of docPath & ".fdf"
    save front document
    save front document in notesPath as "Notes as FDF"
end tell

This essentially saves the current document while simultaneously exporting an .fdf file. Within the same script, I would like to link the .fdf file to the appropriate citation entry in BibDesk. This would involve:

  • determining the citation entry name associated with the .pdf (maybe search through entries to locate one linked with the front document)
  • check to see if the .fdf file is already linked to it
  • if not, attach .fdf file

I haven't been able to find someone who's done something similar, and really can't get past the first step. I tried writing something basic (assume citation entry is highlighted, assume .fdf file is not linked), which produces no results:

tell application "BibDesk"
   set thePub to selection
   tell thePub
        set theFieldName to "Local-URL-2"
    set value of field theFieldName to fdfPath
   end tell
end tell

Is anyone familiar with Bibdesk applescripts able to help me with the second part of this code?

Thank you very much in advance.

4

2 回答 2

1

以下代码令人满意地回答了我最初的问题。第一部分重申了保存和导出命令。第二部分定位包含链接的 .pdf 文件(Skim 中的前端文档)的引用条目。第三部分将 .fdf 文件附加(链接)到引用条目(感谢CRGreen在此处提供的帮助)。

--save and export .fdf file
tell application "Skim"
    set docPath to path of front document
    set fdfPath to text 1 thru -5 of docPath & ".fdf"
    save front document
    save front document in fdfPath as "Notes as FDF"
end tell

--search for relevant citation entry
tell document 1 of application "BibDesk"
    --sort all publications in library by Cite Key
    set thePubs to (sort (get publications) by "Cite Key")
    -check each publication individually (surely this is not the most efficient way to do this)
    repeat with aPub in thePubs
        --check to see if the .pdf is in the citation entry
        tell aPub
            if linked files contains (POSIX file docPath) then
                set thePub to aPub
                --once the citation is found, exit loop
                exit repeat
            end if
        end tell
    end repeat

    --link the .fdf file to the citation entry (if it isn't already)
    tell thePub
        --if the fdf file exists in the linked file, do nothing
        if linked files does not contain (POSIX file fdfPath) then
            add (POSIX file fdfPath) to end of linked files
        end if
    end tell
end tell

我假设有一种更好的方法可以使用关联的 .pdf 文件搜索引文条目(也许使用 applescript 搜索命令?)。这个解决方案对我有用,但如果你知道解决这个问题的更优雅的方法,请随时提及。

要将脚本映射到键盘快捷键(“command-s”很方便),请参见此处(菜单标题是脚本的名称)。脚本需要首先保存到 ~/Library/Application Support/Skim/Scripts 目录。

我只是在学习applescript,我意识到这对大多数人来说可能是一个非常微不足道的练习,但也许它会帮助另一个初学者。

于 2014-05-26T03:36:07.147 回答
1

我对编写 BibDesk 脚本不太熟悉,但我一直在摸索。大量评论以帮助指导您:

set theFieldName to "Local-URL-2"--generally better not to put
--something like this in a tell block if it isn't necessary

tell application "BibDesk"
    --as you have it, you are simply putting the selection class
    --into a variable. here we reference the specific selection
    --object of the document object:
    set thePubSel to selection of document 1
    --and, since this returns a *list* of pubs, I'm grabbing just the first item
    --(but a loop iterating through every publication in the selection perhaps better)
    set thePub to item 1 of thePubSel

    tell thePub
      set value of field theFieldName of it to fdfPath
    end tell
end tell
于 2014-05-24T16:56:27.270 回答