1

いくつかの背景: 私は、科学雑誌の記事を読んだり注釈を付けたりするために、しばらく BibDesk で Skim を使用してきました。最近、Android タブレットを購入しました。これを使用して、.pdf の読み取りと注釈付けも行いたいと考えています。参照ライブラリEratosthenesezPDF Readerを使用しますDropbox を介してすべてのファイルを同期します。私が抱えている問題は、Skim がデフォルトで注釈を拡張属性ファイルとして保存し、Dropbox を介して他のデバイスからアクセスできないことです。注釈を .fdf ファイルとして保存し、.fdf ファイルを BibDesk の引用エントリにリンクすることで、この問題を回避しました。ezPDF リーダーは .fdf ファイルを注釈としてインポートできます。注釈ファイルが BibDesk エントリにリンクされている場合、.pdf と .fdf の両方をタブレットに簡単にダウンロードできます。何百もの参照でいっぱいの Dropbox フォルダ全体を同期する必要はありません。

これを自動的に行うアップルスクリプトを書きたいのですが、アップルスクリプトは初めてで、始めるのに苦労しています。スキムで「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

このコードの 2 番目の部分を手伝ってくれる Bibdesk アップルスクリプトに詳しい人はいますか?

事前にどうもありがとうございました。

4

2 に答える 2

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 に答える
1

The following code answers my initial question satisfactorily. The first section reiterates the saving and exporting commands. The second section locates the citation entry containing the linked .pdf file (front document in Skim). The third section attaches (links) the .fdf file to the citation entry (thanks to CRGreen for some help here).

--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

I'm assuming that there is a better way to search for the citation entry with the associated .pdf file (maybe using the applescript search command?). This solution works for me, but if you know of a more elegant way to solve this problem, feel free to mention it.

To map the script to a keyboard shortcut ("command-s" is convenient), see here (the menu title is the name of your script). The script needs to first be saved to the ~/Library/Application Support/Skim/Scripts directory.

I'm just learning applescript, and I realize that this may have been a very trivial exercise for most, but perhaps it will help out another beginner.

于 2014-05-26T03:36:07.147 に答える