• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: color name for a label index
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: color name for a label index


  • Subject: Re: color name for a label index
  • From: KOENIG Yvan <email@hidden>
  • Date: Mon, 25 Jun 2012 20:34:50 +0200


Le 25 juin 2012 à 20:01, Nigel Garvey a écrit :

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"}

Well done Nigel.
I put the focus on the customized names and forgot the requirement dedicated to the order.
Getting it requires only an extraneous instruction :

--[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*)

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
end try
end repeat
end tell
end tell
colors_loc
{"Aucun", "Gris", "VertVert", "VioletPurple", "Bleu", "Jaune", "Rouge", "Orange"}
(*
Now put them in the label index order *)
tell result to {item 8, item 7, item 6, item 5, item 4, item 3, item 2}
--> {"Orange", "Rouge", "Jaune", "Bleu", "VioletPurple", "VertVert", "Gris"}

--=====

on get_color_loc(num)
set path2res to "" & (path to library folder from system domain) & "Frameworks:ApplicationServices.framework:Versions:A:Frameworks:HIServices.framework:Versions:A:Resources:"
tell application "Finder" to return localized string ("Label_Name_" & num) from table "Labels" in bundle file path2res
end get_color_loc

--=====
--[/SCRIPT]

The unique advantage is that it doesn't need GUIScripting.

Yvan KOENIG (VALLAURIS, France) lundi 25 juin 2012 20:34:44


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >Re: color name for a label index (From: Nigel Garvey <email@hidden>)

  • Prev by Date: Re: color name for a label index
  • Next by Date: Applescript links
  • Previous by thread: Re: color name for a label index
  • Next by thread: Applescript links
  • Index(es):
    • Date
    • Thread