Applescript question
Michael Terry
formido at mac.com
Sun Jan 18 18:10:21 PST 2004
On Jan 17, 2004, at 3:03 PM, Richard Sandilands wrote:
> I'm wanting to use applescript to re-arrange an outline from this
> (where
> the children are topics and the project is set via a pop-up list in a
> second column):
OK, here's a version that doesn't fall into the same speed traps as
either of the other two. It should be quite a bit faster. Also, it
doesn't ignore rows that are more than two levels deep.
Mike
on run
insertOutline(getRowRecords(), prepNewDoc())
end run
on getRowRecords()
set rowRecsLst to {}
tell front document of application "OmniOutliner" to set {everyTopic,
everyLevel} to {topic, level} of every row
repeat with i from 1 to (count everyTopic)
if everyLevel's item i is 1 then
set colVal to everyTopic's item i
else
tell front document of application "OmniOutliner" to set projName to
row i's cell 3's text
if not my existsProj(rowRecsLst, projName) then
set rowRecsLst to rowRecsLst & {my newRowRec(projName, ""), {}}
end if
my addProjItem(rowRecsLst, projName, my newRowRec(everyTopic's item
i, colVal))
end if
end repeat
return rowRecsLst
end getRowRecords
on prepNewDoc()
tell application "OmniOutliner"
tell (make new document at end)
delete first row
make new column at end with properties {type:plain text, title:""}
return it
end tell
end tell
end prepNewDoc
on newRowRec(t, p)
script
property topicValue : t
property parentValue : p
end script
end newRowRec
on insertOutline(outlineData, parentObj)
using terms from application "OmniOutliner"
repeat with itm from 1 to (count outlineData)
if outlineData's item itm's class is list then
my insertOutline(outlineData's item itm, last row of front document
of application "OmniOutliner")
else
tell parentObj to make new row at end with properties
{topic:outlineData's item itm's topicValue}
tell result
if outlineData's item itm's parentValue is not "" then
set cell 3's text to outlineData's item itm's parentValue
end if
end tell
end if
end repeat
end using terms from
end insertOutline
on addProjItem(lst, name, val)
repeat with i from 1 to (count lst) by 2
if lst's item i's topicValue is name then
set end of lst's item (i + 1) to val
end if
end repeat
return
end addProjItem
on existsProj(lst, proj)
repeat with i from 1 to (count lst) by 2
if lst's item i's topicValue is proj then return true
end repeat
return false
end existsProj
More information about the OmniOutliner-Users
mailing list