Language Swapper -- a script by Yvan Koenig posted on his behalf.


-- This script is for swapping languages in the "International" menu.
-- If there are two languages it swaps them each time the script is run.
-- If there are more than two, it rotates from one to the next and back to the beginning.
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
		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 (value of attribute "AXMenuItemMarkChar" of menu item (kl's item i) is not "") then
							if i = knt then
								set i to 1 (* back to top of list *)
							else
								set i to i + 1 (* switch to next layout *)
							end if
							exit repeat
						end if
					end repeat
					click menu item (kl's item i)
				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