Re: Swap keyboard from "belgium" layout to US
Re: Swap keyboard from "belgium" layout to US
- Subject: Re: Swap keyboard from "belgium" layout to US
- From: Felix Grasser <email@hidden>
- Date: Sat, 22 Apr 2006 10:00:37 +0200
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?
[snip: code + suggestions]
Thank you for all your input Kai. I will have to get back to you on
that on Monday. For some reason, your first script (that I reported
not working on my Dual G5, 1.8GHz, 10.4.6 in the office) is running
just fine here at home on my PB G4, 10.4.6.
I am puzzled.
If that gives you a half-sensible answer, it might be worth trying
this slightly modified (and untested) version of the
'switch_keyboard' handler:
------------------
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
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 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"
------------------
This one does work very smoothly as well (PB G4, 10.4.6). I will test
it in the office on Monday.
Btw, is there a way of calling a cocoa action directly from
AppleScript?
Not directly - 'call method' is defined only in applications that
link to AppleScriptKit (which an AppleScript Studio application
does implicitly). It's possible to make obj-c calls through an
application like Automator:
[snip:code]
However, unless Automator already happens to be open, that could be
a bit of a sledgehammer to crack a nut (especially for just the
occasional, one-line sniff). Another way might be to make a
background-only Studio Application dedicated to offering similar
access - which is pretty much what Daniel Jalkut (of FastScripts/
Clarion fame) did. I believe his app can still be downloaded from:
http://www.red-sweater.com/AppleScriptKit.zip
Thank you for the tip. I downloaded AppleScriptKit from Daniel's
website and will keep it around (together with your instructions) for
future reference.
For now, I think I will stick with calling the method (for the
NSTextView class) by assigning it a custom keyboard shortcut in my ~/
Library/KeyBindings/DefaultKeyBinding.dict file. The rest of the
script uses UI scripting anyway, so I need not be too concerned about
finding a more elegant solution.
However, once the once the spelling window is activated, it is
visible on screen, but I can't manage to actually access the
elements. I.e. the switch_current_lang procedure below does not
work.
Does anyone have an idea as to what I am doing wrong and how one
could successfully switch to another language?
I'm not entirely sure if our spelling windows differ in any
significant way, Felix - but I've cobbled together a possible
alternative for your 'switch_current_lang' handler (which is the
crucial part for this discussion). The modified version (further
below) works fine, here - but when was that ever a guarantee? ;-)
OK - so try this, then. If it doesn't work for you, it might be
worth going off-list to hammer it out - so that we don't bother
these good folks with all the minutiae...
[snip: code]
Hoorrayy! It works fabulously. If my wife was not sleeping in the
other room, I would be doing a very loud happiness dance around the
coffee table now ;-)
Thank you so much again for all your efforts. I will let you know how
your scripts behave on the other machine that refuses to see the
brilliance of it all.
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