omnioutline and applescript

Curt Clifton curt.clifton at mac.com
Mon Jul 3 10:38:40 PDT 2006


Krishna,

On Jul 3, 2006, at 12:07 AM, qas qwes wrote:

> Thanks a lot for reply.The attachable means that you  can create a  
> script and then attach it
> to a program so that script is added to the program's internal menus.

Under OS X 10.4, the system AppleScript menu includes application- 
specific AppleScripts.  Use "/Applications/AppleScript/AppleScript  
Utility" to activate Show Script Menu in menu bar.  Then put your  
script in "~/Library/Scripts/Applications/OmniOutliner Pro".  You may  
need to create some of those subdirectories.  Now when OO is the  
front application, your script will be available in the menu bar  
Script Menu.  Your script will also be available for adding to  
customized toolbars in OO.

> The script is making
> the entity relationship diagram . For this there is an SOP  
> (standard operation procedure) in a
> outline in which entiy  type , entity name and attributes defined  
> in line . The script for your
> kind review is as follows

The best way to speed up AppleScript is by using mass operations  
rather than loops.  (Since your script is related to database, it  
might help to think of this as analogous to using a single SQL  
command with a 'where' clause, versus using a cursor.)  For example,  
you might rewrite your get_entities_list() subroutine from your  
original:

> --subroutine to get the entities list
>
> on get_entities_list()
>      tell front document of application "OmniOutliner Professional"
>           set entities_list to {}
>
>           --making the entities list
>           repeat with i from 1 to row_count
>                --getting the entity name from the entity column
>
>                set entity_name to text of cell 7 of row i
>                --if entity name column text is null or empty
>                if entity_name is not in entities_list and (length  
> of entity_name is not equal
> to 0) then
>                     set end of entities_list to entity_name
>                end if
>           end repeat
>      end tell
>      --returning the list of entities list
>      return entities_list
> end get_entities_list
>

to the following:

on get_entities_list()
	tell application "OmniOutliner Professional"
		tell front document
			-- gets all the non-empty values with a single AppleEvent
			set entities_list to value of cell 7 of (every row whose value of  
cell 7 is not "")
			return my remove_duplicates(entities_list, {})
		end tell
	end tell
end get_entities_list

-- function to remove duplicates that doesn't generate any Apple events
on remove_duplicates(the_list, the_accumulator)
	if (the_list is {}) then return the_accumulator
	if (item 1 of the_list is not in the_accumulator) then
		set the end of the_accumulator to item 1 of the_list
	end if
	return remove_duplicates(rest of the_list, the_accumulator)
end remove_duplicates

The original subroutine generates a separate AppleEvent for every row  
in your outline.  The new subroutine generates just one AppleEvent.   
(If you're familiar with Scheme, the remove_duplicates helper  
function is using tail-recursion to efficiently reduce the list to  
unique items.)

Hopefully you can apply a similar optimization to your  
get_entities_attributes handler.

Cheers,

Curt




More information about the OmniOutliner-Users mailing list