• 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: Swap keyboard from "belgium" layout to US
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Swap keyboard from "belgium" layout to US


  • Subject: Re: Swap keyboard from "belgium" layout to US
  • From: Felix Grasser <email@hidden>
  • Date: Mon, 24 Apr 2006 13:54:01 +0200

Hello Kai,

As I said in my message on Saturday, all your scripts worked perfectly on my PB G4, 10.4.6.

Interesting. I haven't yet had a chance to upgrade from 10.4.5, so it still works fine here. (Perhaps something got dented in 10.4.6.) Do you get a decent result from this next snippet?

------------------
tell application "System Events" to tell menu bar 1 of ¬
	application process "SystemUIServer" to value of ¬
	attribute "AXDescription" of menu bar items

-- OMM:
--> {"AppleScript menu extra", "modem menu extra", "text input menu extra", "battery menu extra", "clock menu extra"}

On the Dual G5 1.8GHz, 10.4.6, I get the following results:

{missing value, "AppleScript menu extra", "text input menu extra", "clock menu extra", "user menu extra"}

Hmm, I have some menubar extras installed -- Texpander, iSync and iMote. Let me investigate a bit further...

It turns out that both iSync and iMote add a "missing value" entry to the list of menu bar items. This seems to trip the script.

If the menu bar items (iSync and iMote) are removed, everything runs smoothly (which was the case on the PB).

Adding a "try" block around the part that checks the menu bar items solves the problem (for both your scripts). The script can change the keyboard layout even if menu bar items are present that do not specify an "AXDescription".

Here is the modified version.

======8><=========
on switch_keyboard to keyboard_layout
	tell application "System Events" to tell menu bar 1 ¬
		of application process "SystemUIServer"
		(* workaround for bug in conditional filter: *)
		repeat with this_menu from 1 to count menu bar items
			try
				tell menu bar item this_menu to if ¬
					(get value of attribute "AXDescription") ¬
						is "text input menu extra" then
					click (* open menu *)
					tell menu item keyboard_layout of ¬
						menu 1 to if exists then return click
					cancel (* operation failed: close menu *)
					exit repeat
				end if
			end try
		end repeat
	end tell
	beep (* indicate that a failure occurred *)
	error number -128 (* cancel script execution *)
end switch_keyboard

switch_keyboard to "U.S."
delay 2 (* demo only: do some stuff *)
switch_keyboard to "Belgian"
======><8=========


Thanks again so much for your help. It is so wonderful to finally have this up and running.


Felix _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Re: Swap keyboard from "belgium" layout to US (From: "Gary (Lists)" <email@hidden>)
 >Re: Swap keyboard from "belgium" layout to US (From: kai <email@hidden>)
 >Re: Swap keyboard from "belgium" layout to US (From: Felix Grasser <email@hidden>)
 >Re: Swap keyboard from "belgium" layout to US (From: kai <email@hidden>)

  • Prev by Date: newbie question: AppleScript and hashbang
  • Next by Date: Re: Why do I get this error?
  • Previous by thread: Re: Swap keyboard from "belgium" layout to US
  • Next by thread: Check FTP file
  • Index(es):
    • Date
    • Thread