View Single Post
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 01:08 AM.. Reason: Added code line - sorts selected column (as well as the sequence of its popup values in the column-type inspector)