読者です 読者をやめる 読者になる 読者になる

大文字のみの論文タイトルを小文字を含むものに変換するAppleScript

Mac

ApJなんかでBibTeXのcitationを持ってくると、論文タイトルが全部大文字になっていたりします。例えばここだと、以下の 1. のようになっているべきところが 2. のようになっています。

  1. Fermi Observations of Cassiopeia and Cepheus: Diffuse Gamma-ray Emission in the Outer Galaxy
  2. FERMI OBSERVATIONS OF CASSIOPEIA AND CEPHEUS: DIFFUSE GAMMA-RAY EMISSION IN THE OUTER GALAXY

これだとBibDeskに登録したときなどに読みづらいので、小文字を含んだ1.の表記に変更したくなります。

しかし毎回手でやるのも面倒なので、http://macscripter.net/viewtopic.php?id=24753 を参考にした AppleScript を作成しました。

set orgTitle to (the clipboard)
set newTitle to {}
repeat with myWord in (words of orgTitle)
    set firstLetter to character 1 of myWord
    considering case
        if firstLetter is not in "ABCDEFGHIJKLMNOPQRSTUVWXYZ" then set firstLetter to makeUPPER(firstLetter)
        --make the rest of the letters lower case
        if length of myWord > 1 then
            set lowerletters to text 2 thru (length of myWord) of myWord
            set lowerletters to makelower(lowerletters)
        else
            set lowerletters to ""
        end if
    end considering
	if myWord is in {"ABOUT", "ABOARD", "ABOVE", "ACROSS", "AFTER", "AGAINST", "ALONG", "AMONG", "AROUND", "AS", "AT", "BEFORE", "BEHIND", "BELOW", "BENEATH", "BESIDE", "BESIDES", "BETWEEN", "BEYOND", "BUT", "BY", "DOWN", "DURING", "FOR", "FROM", "IN", "INSIDE", "INTO", "NEAR", "OF", "OFF", "ON", "ONTO", "OPPOSITE", "OUT", "OUTSIDE", "OVER", "PAST", "SINCE", "THAN", "THROUGH", "THROUGHOUT", "TILL", "TO", "TOWARD", "UNDER", "UNDERNEATH", "UNTIL", "UP", "UPON", "VIA", "WITH", "WITHIN", "WITHOUT"} then
        if newTitle is not {} then
            set firstLetter to makelower(firstLetter)
        end if
    end if
    set end of newTitle to firstLetter & lowerletters
end repeat

set AppleScript's text item delimiters to {space}
set the clipboard to newTitle as text
set AppleScript's text item delimiters to {}

on makeUPPER(aLetter)
    considering case
        set myChar to offset of aLetter in "abcdefghijklmnopqrstuvwxyz"
        if myChar > 0 then
            return character myChar of "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        else
            return aLetter
        end if
    end considering
end makeUPPER

on makelower(theText)
    set newText to ""
    repeat with loop from 1 to (length of theText)
        set newText to newText & lower(character loop of theText)
    end repeat
    return newText
end makelower

on lower(aLetter)
    considering case
        set myChar to offset of aLetter in "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        if myChar > 0 then
            return character myChar of "abcdefghijklmnopqrstuvwxyz"
        else
            return aLetter
        end if
    end considering
end lower

のような AppleScript を ~/Library/Application Support/BibDesk/Scripts/ToLower.scpt として保存します。

そうすると、BibDesk のメニューから、この script を呼び出せます。既にコピーしてクリップボード上にある大文字の論文タイトルが、小文字を含むものに置換されます。

主要な前置詞は行頭以外では小文字になるようにしています。ここは好み。