AppleScript questions

Nicholas Riley njriley at uiuc.edu
Fri Aug 22 13:53:10 PDT 2003


On Fri, Aug 22, 2003 at 10:07:36AM -0700, Timothy J. Wood wrote:
> 
> On Friday, August 22, 2003, at 08:25  AM, Nicholas Riley wrote:
> >- In the first case where the topic is empty, the topic doesn't appear
> >until I manually move somewhere else in the outline.
> 
>   This is a known bug that I've got a test case written up for and it 
> will be fixed in a future release.

Great!

>   I'm still an AppleScript novice, so someone else may have a better 
> answer than I do :)

I don't claim to be an expert, especially at implementation.

>   'after' isn't well defined here in a creation context -- if you say 
> 'row after row', do you mean to insert as a sibling (same indention 
> level) or a uncle (sibling of your parent).  If you are inserting after 
> a row in the middle of a level (i.e., the second of three children), 
> then clearly a sibling makes sense.  But, if it is the last child, then 
> it isn't as clear (although I guess sibling makes most sense to me as I 
> think about it :)

Yes, a sibling is what I mean.  I think it'd be pretty consistent, if
you can get it to work.  Otherwise, if you can make the sibling index
an accessible property (as James Spahr mentions), then the existing
terminology would be acceptable.

>   If I run the script you've given, as written on a new document (with 
> my 'end editing hack' from above), then the first time I run it it sets 
> the date.  The second time I get an error trying to get the parent of 
> the selected row.  I'm not exactly sure what effect you are trying to 
> achieve, so I'm not sure what the best fix is :)

The later script I posted should work fine for any document.  I've
fixed it to add the font setting as you mentioned.

It would be nice, and consistent IMO, if the parent of top-level items
was considered the root, and if the root were able to be specified as
a selectable row (it would cause no item to be apparently selected,
which is fine by me).  That'd cut out some of the logic in my script
below.

>   But, yes, it would be much nicer if the row defaulted to using the 
> level styles defined in the document.  I'll add some test cases for 
> this and add it to the list of stuff to get fixed.

Terrific.  Thank you so much for your commitment to this.  Here's the
final script (for now)...

on fixFont(theRow)
    using terms from application "OmniOutliner"
        set theRow's topic's font to "Lucida Grande"
        set theRow's topic's size to 11
    end using terms from
end fixFont

tell front document of application "OmniOutliner"
    local theDate, theRow
    set theDate to (do shell script "date '+%A, %e %B %Y'")
    set theRow to selected row
    if not (exists selected row) then
        set theRow to make new row at end of children of root with properties {topic:theDate}
        set selected row to theRow
        my fixFont(theRow)
    else if theRow's topic is "" then
        set theRow's topic to theDate
        my fixFont(theRow)
        set the selected row to theRow
        set the selected row to theRow
    else
        local theParent, newRow
        try
            set theParent to theRow's first parent
        on error
            set theParent to root
        end try
        set newRow to make new row at end of children of theParent with properties {topic:theDate}
        my fixFont(newRow)
        move newRow to after theRow
        -- XXX selection is still broken
    end if
end tell

-- 
=Nicholas Riley <njriley at uiuc.edu> | <http://www.uiuc.edu/ph/www/njriley>
        Pablo Research Group, Department of Computer Science and
  Medical Scholars Program, University of Illinois at Urbana-Champaign



More information about the OmniOutliner-Users mailing list