【问题标题】:BibDesk script to link Skim annotations to citation entryBibDesk 脚本将 Skim 注释链接到引文条目
【发布时间】:2014-05-24 06:51:58
【问题描述】:

一些背景知识:我使用 Skim 和 BibDesk 有一段时间了,用于阅读和注释科学期刊文章。最近,我购买了一台安卓平板电脑,也想用它来阅读和注释 .pdf 文件。我使用参考库EratosthenesezPDF Reader 并通过Dropbox 同步所有文件。我遇到的问题是,Skim 默认将注释存储为扩展属性文件,其他设备无法通过 Dropbox 访问这些文件。我通过将注释保存为 .fdf 文件然后将 .fdf 文件链接到 BibDesk 中的引文条目来解决此问题。 ezPDF 阅读器可以将 .fdf 文件作为注释导入,如果注释文件链接到 BibDesk 条目,则 .pdf 和 .fdf 都可以轻松下载到平板电脑,而无需同步包含数百个参考的整个 Dropbox 文件夹。

我想编写一个自动执行此操作的 applescript,但我对 applescript 非常陌生,并且很难开始。我已经编写了以下脚本,以便在浏览时按下“command-s”时执行:

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

这实质上是在导出 .fdf 文件的同时保存当前文档。在同一个脚本中,我想将 .fdf 文件链接到 BibDesk 中的适当引用条目。这将涉及:

  • 确定与 .pdf 关联的引文条目名称(可能搜索条目以找到与前面文档链接的条目)
  • 检查 .fdf 文件是否已链接到它
  • 如果没有,请附上 .fdf 文件

我一直没能找到做过类似事情的人,而且真的无法迈出第一步。我尝试写一些基本的东西(假设引用条目被突出显示,假设 .fdf 文件未链接),但没有产生任何结果:

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

是否有熟悉 Bibdesk applescripts 的人能够帮助我完成此代码的第二部分?

非常感谢您。

【问题讨论】:

    标签: applescript bibtex fdf


    【解决方案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
    

    【讨论】:

    • BibDesk 看起来(就像 Skim 一样)在其 AppleScript 集成方面相当出色。我建议查看 BibDesk 网站上提供的脚本示例。
    • 非常感谢您的帮助 - 我特别感谢您对代码的大量评论。您提供的代码是对我编写的代码的改进,但不幸的是我的原始代码有问题;在“Local-URL-2”字段中存储文件名不会将文件链接到条目。我已经解决了这部分问题,如下面的回答所示。但是,我仍然没有弄清楚如何识别.pdf文件对应的引用条目。
    【解决方案2】:

    以下代码令人满意地回答了我最初的问题。第一部分重申了保存和导出命令。第二部分定位包含链接的 .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”很方便),请参阅here(菜单标题是脚本的名称)。脚本需要首先保存到 ~/Library/Application Support/Skim/Scripts 目录。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-18
      • 1970-01-01
      • 2013-12-12
      • 1970-01-01
      • 1970-01-01
      • 2015-08-04
      相关资源
      最近更新 更多