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 > OmniOutliner > OmniOutliner 3 for Mac
FAQ Members List Calendar Today's Posts

 
Column Popup Sorter Thread Tools Search this Thread Display Modes
A while ago I asked if anyone had a script that would sort the popup list of a column. I think it went unanswered. I finally had a chance to pull one together myself. Let me know if there is anything I can do for speed or structure...

tell application "OmniOutliner Professional"
tell front document
set enumcount to count of enumerations of column "Assigned"
display dialog enumcount
set x to 1
repeat until x = enumcount
set y to x + 1
set firstName to the name of enumeration x of column "Assigned"
set secondName to the name of enumeration y of column "Assigned"
if firstName > secondName then
--- swap
set name of enumeration y of column "Assigned" to firstName
set name of enumeration x of column "Assigned" to secondName
set x to 1 -- start agan
else
set x to x + 1
end if
end repeat
end tell
end tell
 
A found a better way is to sort as you add them... See below...

tell application "OmniOutliner Professional"
tell front document
display dialog "Enter new Assigned..." buttons {"Cancel", "Add"} default button 2 default answer "" with title "Assigned"
if button returned of result is "Add" then
set theAssigned to text returned of result
if exists (enumerations of column "Assigned" whose name contains theAssigned) then
display dialog "This Assigned Name Already exsists"
else
set enumcount to count of enumerations of column "Assigned"
set x to 1
repeat until x = enumcount
if theAssigned < the name of enumeration x of column "Assigned" then
make new enumeration at after enumeration (x - 1) of column "Assigned" with properties {name:theAssigned}
exit repeat
else
set x to x + 1
end if
end repeat
end if

end if

end tell
end tell
 
This works faster and avoids the problem of changing the name of an existing popup item you may already have designated for something in your outline:

----------------------------------
set column_name to "Author" -- you can change the name of the column here

tell application "OmniOutliner Professional"
tell front document
set enumcount to count of enumerations of column column_name
set enumnames to (name of every enumeration of column column_name)

-- Sort the Names Alphabetically to choose from
set old_delims to AppleScript's text item delimiters
set AppleScript's text item delimiters to {ASCII character 10} -- always a linefeed
set list_string to (enumnames as string)
with timeout of 10000 seconds
set new_string to do shell script "echo " & quoted form of list_string & " | sort -f"
end timeout
with timeout of 10000 seconds
set new_list to (paragraphs of new_string)
end timeout
set AppleScript's text item delimiters to old_delims
set enumnames to new_list

repeat with y from 1 to enumcount
repeat with x from 1 to enumcount
set x_name to the (name of enumeration x of column column_name)
set y_name to the (item y of enumnames) as string
if y_name = x_name then
--- swap
set index of enumeration x of column column_name to y
end if
end repeat
end repeat
end tell
end tell
---------------------------------------------
 
A slightly simplified approach (may be marginally faster) which sorts the popup values of the currently selected popup column.

Code:
-- Ver 0.2

-- Sorts the pop-up values in the column-type inspector for the selected column

tell application id "OOut"
	-- GET A REFERENCE TO THE FIRST SELECTED POPUP COLUMN
	try
		set oCol to first selected column of front document where type = popup
	on error
		display alert "No popup column selected"
		return
	end try
	
	-- DO NOTHING UNLESS THE COLUMN HAS MORE THAN ONE POPUP VALUE
	tell oCol
		tell (enumerations)
			set lngPops to count
			if lngPops < 2 then return
			
			-- READ THE NAME AND ID OF EACH POPUP VALUE INTO A PAIRED LIST
			set {lstName, lstID} to {name, id}
			repeat with i from 1 to lngPops
				set item i of lstID to item i of lstName & tab & item i of lstID
			end repeat
		end tell
		
		-- GET A LIST OF POPUP IDs SORTED IN THE ORDER OF THE CORRESPONDING POPUP NAME
		set {dlm, my text item delimiters} to {my text item delimiters, linefeed}
		set lstID to paragraphs of (do shell script ("echo " & quoted form of (lstID as string)) & " | sort -k 1 -f  | cut -f 2")
		set my text item delimiters to dlm
		
		-- ASSIGN INDEX NUMBERS TO THE POPUP VALUES IN THEIR SORTED ORDER
		repeat with i from 1 to lngPops
			set index of (enumeration id (item i of lstID)) to i
		end repeat
		
		set sort order to ascending
	end tell
end tell
--

Last edited by RobTrew; 2012-02-02 at 12:08 AM.. Reason: Added code line - sorts selected column (as well as the sequence of its popup values in the column-type inspector)
 
Thank you!

____________________________
 
 




Similar Threads
Thread Thread Starter Forum Replies Last Post
Paste from Word Column to OO Column jhlindstrom OmniOutliner 3 for Mac 1 2011-02-10 03:05 PM
Popup menu column, set value for lots of rows at once? amorya OmniOutliner 3 for Mac 2 2009-10-13 11:49 AM
Problem with popup column davidinva OmniOutliner 3 for Mac 2 2009-09-24 06:25 AM
Popup on top runard OmniWeb General 4 2007-07-04 05:43 AM


All times are GMT -8. The time now is 04:06 AM.


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