The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniOutliner 3 for Mac (http://forums.omnigroup.com/forumdisplay.php?f=9)
-   -   Column Popup Sorter (http://forums.omnigroup.com/showthread.php?t=5773)

gcrump 2007-11-24 09:29 AM

Column Popup Sorter
 
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

gcrump 2007-11-26 12:04 PM

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

ToddV 2011-06-30 02:36 PM

re: Column Popup Sorter
 
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
---------------------------------------------

RobTrew 2011-07-27 06:58 AM

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[/CODE]

[COLOR="White"]--[/COLOR]

marta12 2011-07-29 08:34 AM

Thank you!

____________________________


All times are GMT -8. The time now is 05:56 AM.

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