adding rows in scripts

Curtis Clifton curt.clifton at mac.com
Fri Jan 14 09:28:43 PST 2005


On Jan 14, 2005, at 10:11 AM, sophos at mailcan.com wrote:

> After hours of battling through various script experiments that didn't 
> work, I managed to write a script that splits a multi-line topic into 
> multiple rows. I could only figure out how to insert the rows at the 
> end of the current section.  I really wanted to insert them right 
> after the selected row.  Any suggestions?
>
> BTW, this script is really useful after a paste of multiple lines of 
> text into an OOv3 row topic.

Neat idea.  You inspired me to find the solution to your question.  The 
key is to make the new rows "after child theOffset", where theOffset is 
initially the index of the selected row but is incremented after 
insertion.  Without incrementing theOffset the rows are added in 
reverse order.

But I couldn't help gold plating a bit along the way.  Below is my 
revised version of your script.  It includes a few enhancements:

- checks to make sure a row is selected
- doesn't do any work if the selected row has only one paragraph
- inserts the rows after the originally selected row
- deletes the originally selected row (but only if it was childless)
- selects the newly created rows

I tried to document the script so that one could readily remove any of 
the new features.

tell front document of application "OmniOutliner Professional"
	try
		set v_selrow to selected row 1
	on error
		beep
		display dialog "You must select a row to split." buttons {"Close"} 
default button "Close"
		return
	end try
	
	set v_parent to parent of v_selrow
	set v_topic to topic of v_selrow
	set theParagraphs to every paragraph in v_topic
	
	-- Nothing to do? Then do it.
	if (count of theParagraphs) is 1 then return
	
	-- Creates the new rows
	set theOffset to (index of v_selrow)
	repeat with v_p in theParagraphs
		make new row with properties {topic:v_p} at ¬
			after child theOffset of v_parent
		set theOffset to theOffset + 1
	end repeat
	
	-- Stores some info before deleting the old row
	set theOffset to (index of v_selrow)
	set theCount to (count of theParagraphs)
	if ((count of children of v_selrow) is 0) then
		delete v_selrow
		-- Selects all the new rows
		select children theOffset thru (theOffset + theCount - 1) of v_parent
	else
		beep
		display dialog "Original row not deleted because it has children." 
buttons {"OK"} default button "OK"
	end if
	
end tell

Share and enjoy,

Curt

----------------------------------
Curtis Clifton, PhD Candidate
Dept. of Computer Science, Iowa State University
http://www.cs.iastate.edu/~cclifton




More information about the OmniOutliner-Users mailing list