Help with Merge selected rows script

Hi, I want to use the merge selected rows script that is part of the useful scripts bundle. The script fails in the following line:

duplicate (text of (cell j of (item i of selected rows))) to after last character of text of cell j of theFirstSelected

And the error says that it is unable to move to the container.

I asked for help to Omni’s human support but the answer was to update the script with the changes for version 4.

I want to ask if somebody has made this changes to the script and have it working in version 4. I do not have any experience programming in applescript and would like to save some time.

Best regards

Carlos

Can you post the entire applescript as you have it?

Hi, this is the error message:

AppleScript reported the following error:

The operation couldn’t be completed. /Users/csolis/Library/Application Scripts/com.omnigroup.OmniOutliner4/Merge Selected Rows.scpt: execution error: OmniOutliner got an error: Can‚Äôt make or move that element into that container. (-10024)

And the script is the following:

tell front document of application “OmniOutliner”
set theCount to (count of selected rows)
if theCount < 2 then
display dialog “You need to select at least two rows to use this script.” buttons “Cancel” default button “Cancel”
end if

-- this should catch notes and rich text columns - checkboxes, pop-ups, and so forth are way too hard to do.
set theColumnCount to (count of items in (every column whose column type is styled text))
set theFirstSelected to first item of selected rows

-- run through the selected rows/columns and add newline characters in a way that preserves the styles
repeat with i from 1 to theCount
	repeat with j from 1 to theColumnCount
		-- skip the last row, because we don't need a newline there
		if i < theCount then
			if ((count of characters of (text of (cell j of (item i of selected rows)))) > 0) then
				duplicate last character of (text of (cell j of (item i of selected rows))) to after last character of (text of (cell j of (item i of selected rows)))
				get last character of (text of (cell j of (item i of selected rows)))
				set text of last character of (text of (cell j of (item i of selected rows))) to "

"
end if
end if

		-- now move the text of each cell up into the first selected row, skipping the first row
		if i > 1 then
			duplicate (text of (cell j of (item i of selected rows))) to after last character of text of cell j of theFirstSelected
		end if
	end repeat
	
	-- now we delete the items that aren't the first item as we loop through
	if i is greater than or equal to 2 then
		set theList to every selected row
		delete row id (id of (item i of (every selected row)))
	end if
end repeat

end tell

best regards
Carlos

I have no way to test the original script, but the script below works similar to the description.
You can view screenshots of the result here.

Edit: First script did not take into account that the first selected row may not always be the first row in the document. The below script remedies this.

tell front document of application "OmniOutliner"
	
	if (count of selected rows) < 2 then
		display dialog "Select rows to merge." buttons "Cancel" default button "Cancel"
	end if
	
	set row_start to (index of first selected row) --skip non-selected rows
	set row_end to (index of last selected row) --record last row for deletion
	
	repeat with n from 1 to (count of selected rows) --# of rows selected
		
		set row_one to text of cells of first selected row --make list from first row
		set row_c to 1 --change to 0 to include notes
		
		repeat with i from 1 to count row_one --# of items (columns) in first row
			
			set row_c to row_c + 1
			
			if n > 1 then
				set row_copy to text of cells of row (n + row_start - 1) --make list from next row
				
				set {l1, l2} to {row_one, row_copy} --merge list items
				set newlist to {}
				repeat with i from 1 to (count l1)
					set end of newlist to ((item i of l1) as text) & " " & item i of l2
				end repeat
				
				set value of cell row_c of first selected row to item row_c of newlist --insert merged items
				
				if row_c is (count row_one) then exit repeat --stop at last column
			end if
			
		end repeat
	end repeat
	
	delete (rows (row_start + 1) thru (row_end))
	
end tell

Hello,

This works really well except when the script is used on indented rows… When the script is used on indented rows it seems to copy the text from the documents second row rather than the selected second row… I’m a bit of a newbie and am guessing there’s a quick fix but i can’t figure it out!
Any idea’s?

Cheers & thanks for your previous efforts in putting the script together,

Ben

Ok so I finally came up with a working script based mainly off DrLulz’s original script except this one now performs in documents that have nested rows or rows with children. Took me an obscene amount of time as I’m learning Applescript as I got but am happy to finally has a workflow coming together.
I’ve posted the script on github at the following address for anyone to use.

Updated with new link

1 Like

FYI, the link you’ve provided here doesn’t work as is, generating a 404 error. But if you cut off everything from '/tree/ onward, it seems to work fine.

Good idea though.
Regards,
Ken

Arrgh, right you are, I’ve just updated it with the correct link, Cheers for the heads up Mockman.

Ben