Sorry for the delay, I was in Las Vegas for a job interview. Please, if anyone reads this, please hire me. Please. eyeballs DEVONtechnologies, who could use a… cook, or something, because Lord Knows I can’t program my way out of Bill DeVille’s toupée
Anyway, I feel your pain after using this myself for a few days. Your note was all it took to make me think “hey, I should script that.” And then I grabbed myself some apple cider and started scriptin’. And, as per usual, what seemed to be a simple task turned into a raging pain in the ass, since I am working on Tiger and using its Unicode-crippled AppleScript and not the Unicode-savvy AppleScript of Leopard. This should still work on Leopard, though, and it’s a quick change if it doesn’t.
Select some articles or groups in your database (named “12. Cow” or “XIX. Moo” or whatever) and run this script, and it’ll replace the initial number (everything before the “.”) with proper Roman numerals. “XII” is rendered as X + II, not XII as above, because I didn’t feel like making algorithm exceptions just to use all of the provided Unicode characters It nicely follows the “order of magnitude” rule in constructing roman numerals – ie, it’ll correctly write 99 as XCIX and not IC and 1999 as MCMXCIX, not MIM. It only goes up to 3999, but if you’re using Roman numerals to count that high, well, that’s just ridiculous.
tell application "DEVONthink Pro"
set theSelection to the selection
set theDelimiter to "." -- Change this if you're using a colon or something else to separate the Roman numerals from the rest of the article/group title.
set AppleScript's text item delimiters to theDelimiter
repeat with thisSelection in theSelection
set thisTitle to the name of thisSelection
set theTitleParts to the text items of thisTitle
set theNumeralPart to text item 1 of theTitleParts
try
if the first character of theNumeralPart is in "MDCLXVI" then set theNumeralPart to my GetArabicOf(theNumeralPart) -- Convert it to Arabic numbers first if it's in Roman numerals already, to make this easier.
if the first character of theNumeralPart is in "0123456789" then set theNumeralPart to my GetRomanOf(theNumeralPart) -- Convert that Arabic numeral to a Unicode Roman string.
end try
set theNewName to theNumeralPart & theDelimiter & (items 2 through -1 of theTitleParts) as Unicode text
set the name of thisSelection to theNewName
end repeat
end tell
on GetRomanOf(theNumber)
set theRomanThousands to {"", «data utxt216F» as Unicode text, («data utxt216F» as Unicode text) & «data utxt216F» as Unicode text, ((«data utxt216F» as Unicode text) & «data utxt216F» as Unicode text) & «data utxt216F» as Unicode text}
set theRomanHundreds to {"", «data utxt216D» as Unicode text, («data utxt216D» as Unicode text) & «data utxt216D» as Unicode text, ((«data utxt216D» as Unicode text) & «data utxt216D» as Unicode text) & «data utxt216D» as Unicode text, («data utxt216D» as Unicode text) & «data utxt216E» as Unicode text, «data utxt216E» as Unicode text, («data utxt216E» as Unicode text) & «data utxt216D» as Unicode text, ((«data utxt216E» as Unicode text) & «data utxt216D» as Unicode text) & «data utxt216D» as Unicode text, (((«data utxt216E» as Unicode text) & «data utxt216D» as Unicode text) & «data utxt216D» as Unicode text) & «data utxt216D» as Unicode text, («data utxt216D» as Unicode text) & «data utxt216F» as Unicode text}
set theRomanTens to {"", «data utxt2169» as Unicode text, («data utxt2169» as Unicode text) & «data utxt2169» as Unicode text, ((«data utxt2169» as Unicode text) & «data utxt2169» as Unicode text) & «data utxt2169» as Unicode text, («data utxt2169» as Unicode text) & «data utxt216C» as Unicode text, «data utxt216C» as Unicode text, («data utxt216C» as Unicode text) & «data utxt2169» as Unicode text, ((«data utxt216C» as Unicode text) & «data utxt2169» as Unicode text) & «data utxt2169» as Unicode text, (((«data utxt216C» as Unicode text) & «data utxt2169» as Unicode text) & «data utxt2169» as Unicode text) & «data utxt2169» as Unicode text, («data utxt2169» as Unicode text) & «data utxt216D» as Unicode text}
set theRomanOnes to {"", «data utxt2160» as Unicode text, «data utxt2161» as Unicode text, «data utxt2162» as Unicode text, «data utxt2163» as Unicode text, «data utxt2164» as Unicode text, «data utxt2165» as Unicode text, «data utxt2166» as Unicode text, «data utxt2167» as Unicode text, «data utxt2168» as Unicode text}
set theResult to ""
repeat with theCounter from 1 to (count (theNumber as string))
set theResult to item (((item -theCounter of (theNumber as string)) as integer) + 1) of item theCounter of {theRomanOnes, theRomanTens, theRomanHundreds, theRomanThousands} & theResult
end repeat
end GetRomanOf
on GetArabicOf(theNumber)
set theResult to 0
repeat with theCounter from 1 to count theNumber
set theResult to theResult + (item (offset of (item theCounter of theNumber) in "MDCLXVI") of {1000, 500, 100, 50, 10, 5, 1}) * (((((offset of (item (theCounter + 1) of (theNumber & "@")) in "MDCLXVI@") ≥ (offset of (item theCounter of theNumber) in "MDCLXVI")) as integer) * 2) - 1)
end repeat
end GetArabicOf
Hope that helps Note that it’ll take either a roman numeral or a arabic numeral and convert it to the sexxxy Unicode if it’s the first item. Normal strings will be ignored (but suffixed with three delimiters for some reason I don’t feel like troubleshooting) unless they begin with M,D,C,L,X,V or I. So as always, back up before using a KalisphoenixScript and use only on articles that begin with an appropriate arabic or text numeral prefix.