Is it possible to switch to a specific keyboard layout via `defaults`, *.plist or similar?
~/Library/Preferences/ByHost/com.apple.HIToolbox.*.plist has an AppleSelectedInputSources key, but modifying it directly doesn't seem to actually change the layout.

Most of the solutions posted at MacScripter just use UI scripting as well.

There's a small Objective-C utility called changeInput though that should change the layout almost instantly.