can children inherit text from parent?
Say I have a parent topic named "Opportunities"
And it has the following children: Jobs Grants Offers Is there a way I can make these children automatically include the parent's name? something like this-- Opportunities: Jobs Opportunities: Grants Opportunities: Offers without having to type in opportunities. Thanks for your help |
You can run this simple script while selecting the parent rows.
(It will, however, remove any text formatting from the children which receive the prefix ...) [CODE]tell application id "com.omnigroup.OmniOutlinerPro3" tell front document set lstSeldParents to (selected rows where its children is not children of its children) repeat with oRow in lstSeldParents set strTopic to (topic of oRow) repeat with oChild in children of oRow set strChildTopic to topic of oChild if strChildTopic does not start with strTopic then set the topic of oChild to strTopic & ": " & strChildTopic end if end repeat end repeat end tell end tell[/CODE] |
[QUOTE=RobTrew;87585]You can run this simple script while selecting the parent rows.
(It will, however, remove any text formatting from the children which receive the prefix ...) [/QUOTE] It's a pretty rare opportunity to improve on a script by RobTrew, so I'm going to grab it :-) If you want your children to retain their formatting, and have the prefix from the parent rows retain its formatting as well, this mashup of Rob's script and the Merge Selected Rows script should do the trick. It won't win any programming style competitions, though! [code] tell application id "com.omnigroup.OmniOutlinerPro3" tell front document set lstSeldParents to (selected rows where its children is not children of its children) if ((count of lstSeldParents) < 1) then display dialog "You need to select at least one parent row to use this script." buttons "Cancel" default button "Cancel" end if repeat with oRow in lstSeldParents set strTopic to (topic of oRow) if ((count of characters of (topic of oRow)) > 0) then duplicate last character of (topic of oRow) to after last character of (topic of oRow) set text of last character of (topic of oRow) to ":" duplicate last character of (topic of oRow) to after last character of (topic of oRow) set text of last character of (topic of oRow) to " " end if repeat with oChild in children of oRow set strChildTopic to topic of oChild if strChildTopic does not start with strTopic then duplicate topic of oRow to before first character of topic of oChild end if end repeat delete last character of (topic of oRow) delete last character of (topic of oRow) end repeat end tell end tell[/code] |
Thank you ! (I tried and failed to find the right target for the duplication - a relief to see that it is possible).
I shall add it to my list of enlightening scripts :-) |
As a PS, if formatting is an issue, and the parent format differs from the child format, you can choose between copying the formatting of the parent row to the prefix for the child, or preserving the formatting of the child.
Whpalmer4 's script already works very well for the former option. (A bold row with italic children will confer a bold prefix on each child, preserving the italic formatting of their main text). If, however, you wanted the children to simply inherit the prefix text from the parent row, preserving their own formatting for prefix as well as main text, you could try the following variant on whpalmer's script: [CODE]-- Variant in which both prefix and main text of each child row preserve child row formatting -- (For cases where parent and child row formatting differ) tell application id "com.omnigroup.OmniOutlinerPro3" tell front document set refSeldParents to (a reference to (selected rows where its children is not children of its children)) if ((count of refSeldParents) < 1) then display dialog "You need to select at least one parent row to use this script." buttons "Cancel" default button "Cancel" end if repeat with oRow in refSeldParents set strTopic to (topic of oRow as string) & ": " set lngChars to length of strTopic -- Duplicate the parent text as a prefix for first child -- (character by character retaining child formatting) set refChiln to children of oRow set oChild to first item of refChiln set refChildTopic to (a reference to topic of oChild) if refChildTopic does not start with strTopic then set refFirst to (a reference to first character of refChildTopic) repeat with iChar from lngChars to 1 by -1 duplicate refFirst to before refFirst set text of refFirst to character iChar of strTopic end repeat end if -- Now duplicate the prefix of the first child to the start of any siblings -- (a bit faster) set lngChildren to count of refChiln if lngChildren > 1 then set refTemplate to (a reference to characters 1 thru lngChars of refChildTopic) repeat with iSibling from 2 to lngChildren set refSibTopic to (a reference to topic of item iSibling of refChiln) if refSibTopic does not start with strTopic then ¬ duplicate refTemplate to before first character of refSibTopic end repeat end if end repeat end tell end tell [/CODE] |
i haven't had a chance to try these yet, but damn guys. impressive! thank you very much for the help.
|
All times are GMT -8. The time now is 06:29 AM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.