Hello
Read the given script.
There is no need to know the menu name as it is not used to grab it.
The menu itself is identified thru its attribute “AXDescription” whose value is: “text input menu extra”.
After that we must grab the name of the menu items.
When done, to select the Dvorak one, we just need to search in the menu item list one which contains “Dvorak”.
If the active layout is Dvorak, getting the properties of the Layout menu will return:
{position:{1244, 0}, maximum:missing value, name:missing value, size:{30, 22}, subrole:“AXMenuExtra”, class:menu bar item, minimum value:missing value, enabled:true, selected:false, role:“AXMenuBarItem”, help:missing value, title:missing value, value:“Dvorak”, entire contents:{}, description:“menu extra”, focused:missing value, orientation:missing value}
But, as explained in detail by kai (thank you kai) we may not use this value in a search.
Here is a variation on the script which activates the Dvorak layout:
tell application "System Events" to tell process "SystemUIServer"
set _ to get value of attribute "AXDescription" of every menu bar item of menu bar 1
set {k, j} to {count of _, 0}
repeat with i from 1 to k
if _'s item i is "text input menu extra" then
set j to i
exit repeat
end if
end repeat
if j > 0 then
-- get properties of menu bar item j of menu bar 1
tell menu bar item j of menu bar 1
click
tell menu 1
set {lk, kl, i} to {get name of every menu item, {}, 0}
repeat
set i to i + 1
if lk's item i is missing value then exit repeat
set end of kl to lk's item i
end repeat
(* now we have a list of installed layouts *)
set knt to count of kl
if knt > 1 then
repeat with i from 1 to knt
if kl's item i contains "Dvorak" then
(* here we met the "Dvorak" menu item *)
click menu item (kl's item i)
exit repeat
end if
end repeat
end if -- knt > 1
end tell -- to menu 1
end tell -- to menu bar item.
end if -- j > 0
end tell -- to process and System Events
Yvan KOENIG (from FRANCE vendredi 22 septembre 2006 07:26:36)