AppleScript, walking an outline

James Spahr jsp at designframe.com
Sun Jan 6 11:20:59 PST 2002


> The item ID numbers in an outline are now sequential, so you can step
> through an outline one item at a time and the order will be correct

Example:

Here's a script that will take an OO outline and re-create it in Brain
Forest (so you can carry your outlines on your Palm :) )



on procOutline(docNum)
    -- docNum is the OO document number
    
    tell application "OmniOutliner"
        -- get the item count
        set lineCt to the count of (every item in document docNum)
        
    end tell
    
    -- Prep Brain Forest
    
    tell application "BrainForest Professional"
        set thebfDoc to make new document
        set the tree type of thebfDoc to project
        tell thebfDoc
            set show due dates to false
            set show numbering to false
            set show priorities to false
            set new items are action to true
        end tell
        
        set theBFObjs to {thebfDoc}
        set theBFlvl to 1
        
    end tell
    
    repeat with i from 1 to lineCt
        -- walk the outline
        
        tell application "OmniOutliner"
            set txt to every text of item i of document docNum
            set lvl to level of item i of document docNum
            set stt to state of item i of document docNum
            set exp to expanded of item i of document docNum as boolean
        end tell
        
        -- convert the checked state verbage diffs
        set bfdone to false
        if stt is "checked" then
            set bfdone to true
        end if
        
        tell application "BrainForest Professional"
            
            -- check to see if we have indented in one level
            -- we'll keep the skack in a list
            if lvl > theBFlvl then
                try
                    set item lvl of theBFObjs to newLeaf
                on error
                    set theBFObjs to theBFObjs & {newLeaf}
                end try
            end if
            
            -- set the 2 outlines to be on the some level
            set theBFlvl to lvl
            set insertObj to item lvl of theBFObjs
            
            -- make a leaf in BF
            -- Watch the break in this email!
            tell insertObj to set newLeaf to make new tree item
                at end with properties {title:txt, action:true,
                done:bfdone, expanded:exp}
            --reveal newLeaf
        end tell
        
    end repeat
    
    
end procOutline

procOutline(1)




More information about the OmniOutliner-Users mailing list