Applescript question

Michael Terry formido at mac.com
Sat Jan 17 22:51:22 PST 2004


On Jan 17, 2004, at 10:35 PM, BJ Terry wrote:

> Here's what I came up with. It takes 93 seconds to run on my machine 
> for a file with 50 parents, 10 projects, and 700 rows. You can't set 
> the second column to a popup from the applescript interface, because 
> OO doesn't let you set the options, and isn't smart enough to take the 
> text you give it:
>

Well, since I spent all this time working on it, here's mine too: :) On 
a similar test case as BJ's, it takes an unconscionable amount of time. 
I didn't really think Richard might have 700 rows(!) in his document. 
It works fine on small documents, though.


Cheers,
Mike


on run
	set valsLst to {}
	tell application "OmniOutliner"
		tell front document
			repeat with thisRow in (get every row)
				if thisRow's cell 3's text does not start with "Project" then
					set colVal to thisRow's topic
				else
					set projName to thisRow's cell 3's text
					if not my existsProj(valsLst, projName) then
						set valsLst to valsLst & {projName, {}}
					end if
					run script "{topicVal:" & my quoteForAS(thisRow's topic) & ", 
parentVal:" & my quoteForAS(colVal) & "}"
					my addProjItem(valsLst, projName, result)
				end if
			end repeat
		end tell
		tell (make new document at end)
			delete first row
			make new column at end
			my insertOutline(valsLst, it)
		end tell
	end tell
end run

on insertOutline(outlineData, parentRow)
	repeat with itm in outlineData
		tell application "OmniOutliner" --to tell front document
			if itm's class is list then
				my insertOutline(itm, last row of front document)
			else if itm's class is in {Unicode text, string} then
				tell parentRow to make new row at end with properties {topic:itm}
			else if itm's class is record then
				tell parentRow to make new row at end with properties {topic:itm's 
topicval}
				set result's cell 3's text to itm's parentval
			end if
		end tell
	end repeat
end insertOutline

on quoteForAS(str)
	try
		return & str & return as event as script as RGB color
	on error msg
		return "\"" & msg's text from paragraph 2 to paragraph -2 & "\""
	end try
end quoteForAS

on addProjItem(lst, name, val)
	repeat with i from 1 to (count lst) by 2
		if lst's item i 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 is proj then return true
	end repeat
	return false
end existsProj




More information about the OmniOutliner-Users mailing list