View Single Post
Quote:
Originally Posted by Carlos View Post
- is it correct to set the "topic" of a row to the text (or is there another way)
Setting the "topic" is the simple way to get at the text of the cell in the topic column. You can also set the text of a specific cell:

Code:
	set text of topic cell of first selected row to "Hello!"
	set text of cell "French" of first selected row to "Bonjour!"
(Note that "topic cell" always accesses the cell in the topic column—no matter what it's named—while 'cell "French"' will access the cell in the column named "French".)

Quote:
- this is wonderful, because this contains the number that I seem to need: 2+1+2, which is the ID of the current row, which I seem to need when I want to add an attachment (as the ID of the row in this example script)
Oh, sorry if my example led you astray! You don't need a specific id, you just need to tell the text of some cell that you want to make a new attachment. Here's an example of that which is based on your example:

Code:
set myAttachmentPath to "/Applications/OmniOutliner Pro.app/Contents/Resources/HelpImages/oo4mac_aboutbox.png"

tell front document of application "OmniOutliner Pro"
	set targetCell to topic cell of first selected row
	set text of targetCell to "Hello, world! Here's an attachment: "
	tell text of targetCell
		make new file attachment with properties {file name:POSIX file myAttachmentPath, embedded:true} at end of characters
	end tell
end tell
As for the next question:

Quote:
-- is this the way to get to this ID, or are there other ways?
As you already found, "first selected row" will return "child 2 of child 1 of child 2 of document id…" when that's what you have selected. But there's nothing magic about that path of descendents; you can write those same words in your script instead of writing "first selected row". For example, in the above script you could replace the targetCell assignment with:

Code:
		set targetCell to topic cell of child 2 of child 1 of child 2
and you'd update that 2+1+2 cell every time (if it exists), ignoring the current selection.

Hope this helps!