The Omni Group
These forums are now read-only. Please visit our new forums to participate in discussion. A new account will be required to post in the new forums. For more info on the switch, see this post. Thank you!

Go Back   The Omni Group Forums > Developer > AppleScripting Omni Apps
FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
Dealing With Selected Rows / Cells Thread Tools Search this Thread Display Modes
I am playing with putting things into OO4 via applescript. Please note that I am new to apple scripting.

This script does more or less what I want:

Code:
tell application "OmniOutliner"
	set MyDoc to front document
	set myText to "Hello World!"
	-- set the note of selected row to myText
	set note of selected rows of MyDoc to myText
	-- set the cell of selected row to myText
	set topic of selected rows of MyDoc to myText
	
	set curRow to selected rows of MyDoc
end tell
Still, a few questions remain:
- is it correct to set the "topic" of a row to the text (or is there another way)
- in my current document, for a selected row, I get for example

Code:
{child 2 of child 1 of child 2 of document id "aGFw5TYjAVs" of application "OmniOutliner"}
- 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)
-- is this the way to get to this ID, or are there other ways? I played with

Code:
set rowInd to index of first selected row of myDoc
set rowDepth to level of first selected row of myDoc
but I wasn't successful.
 
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!
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes



All times are GMT -8. The time now is 05:29 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.