KOENIG Yvan wrote on Sat, 23 Jun 2012 09:59:47 +0200:
You may try this code :
--[SCRIPT]
set colors_loc to {}
(*
Grab the default localized colors names *)
repeat with i from 0 to 7
copy (my get_color_loc(i)) to end of colors_loc
end repeat
(*Aucun, Gris, Vert, Violet, Bleu, Jaune, Rouge, Orange*)
Hi, Yvan.
To match the order of the label indices returned on my system (Snow
Leopard, English), the above repeat needs to be something like:
repeat with i from 8 to 1 by -1
copy (my get_color_loc(i mod 8)) to end of colors_loc
end repeat
(* {"None", "Orange", "Red", "Yellow", "Blue", "Purple", "Green", "Gray"} *)
set thePlist to (path to preferences from user domain as text) &
"com.apple.Labels.plist"
tell application "System Events"
tell contents of property list file thePlist
(*
Grab the custom color names *)
repeat with i from 1 to 7
try
value of property list item ("Label_Name_" & i)
set item (i + 1) of colors_loc to result
Similarly, this last line has to be:
set item (9 - i) of colors_loc to result
Another approach would be GUI Scripting:
tell application "Finder"
set current panel of (open window of Finder preferences) to Label Preferences panel
end tell
tell application "System Events"
tell application process "Finder"
set labelNames to value of text fields of front window
end tell
end tell
tell application "Finder" to close window of Finder preferences
-- In Preferences display order:
reverse of labelNames
--> {"Red", "Orange", "Yellow", "Green", "Blue", "Purple", "Gray"}
-- In label index order, assuming the same correlation on all systems:
tell labelNames to set labelNames to {item 6, item 7, item 5, item 3, item 2, item 4, item 1}
--> {"Orange", "Red", "Yellow", "Blue", "Purple", "Green", "Gray"}