2011/06/18

Convert DEVONthink tags to MediaWiki categories

DEVONthink has a quite efficient tagging capability. Especially, the autocomplete feature of the tag bar, at the lower part of a DEVONthink window, saves me a lot of time and provides increased consistency in my tags.

Moreover, I maintain a separate page in my wiki for each book or paper that I have read. There I write all my notes and thoughts about each source. MediaWiki's name for tag is category and the required markup code for it is the following:
[[Category:tagName]] 
As I did not want to insert manually the tags for each source twice I wrote an AppleScript, which converts DEVONthink tags to MediaWiki categories. One item should be selected in DEVONthink before executing the script. The result is sent to the clipboard.

The AppleScript code is the following:
--2011-06-18
--http://organognosi.blogspot.com

tell application "DEVONthink Pro"
    set thisSelection to the selection
    if thisSelection is {} then error "Please select something"
    if (length of thisSelection) is greater than 1 then error "Please select only one item"
    set the clipboard to ""
    set newCategories to ""
    repeat with thisItem in thisSelection
        set tagsItem to tags of thisItem
        repeat with eachTag in tagsItem
            set tagForCategory to eachTag
            if tagForCategory is in {"Linked with MediaWiki"} then
                set newCategories to newCategories
            else
                set newCategories to "[[category:" & tagForCategory & "]] "
                set the clipboard to (the clipboard) & newCategories
            end if
        end repeat
    end repeat
end tell

No comments: