Hello,
At the beginning of a script, I would like to have a line that would select a specific active keyboard layout. In other words. how can I script something that would mean:
set keyboard layout to “U.S.”
Thanks in advance.
Robert
Hello,
At the beginning of a script, I would like to have a line that would select a specific active keyboard layout. In other words. how can I script something that would mean:
set keyboard layout to “U.S.”
Thanks in advance.
Robert
Bonjour Adam,
Wow !!! What extensive work to express this simple little request: «set keyboard layout to “U.S.”» !!!
I have tried to follow all the thread, and am not sure to have understood everything. I have tried to keep it simple and kept only the folowing little script and it seems to work:
tell application "System Events" to tell process "SystemUIServer"
tell (get first menu bar item of menu bar 1 whose value of attribute "AXDescription" is "text input menu extra")
click
delay 0.1
click menu item "Canadian - CSAdot.rsrc" of menu 1
end tell
end tell
I need to put this little script at the beginning of my script to be sure that the “Canadian - CSAdot.rsrc” is active for the execution of the rest of the script. At the end I have to change the keyboard back again and select the “TypeIt4Me” keyboard:
tell application "System Events" to tell process "SystemUIServer"
tell (get first menu bar item of menu bar 1 whose value of attribute "AXDescription" is "text input menu extra")
click
delay 0.1
click menu item "TypeIt4Me" of menu 1
end tell
end tell
These 2 scripts do the job, but acts as a «Quickeys script». All menu changes are apparent. You see the menu expand and the different choices being made as if I was mousing it myself. I think there must be a nicer way, that works in the background …
Is there a way to select a different keyboard with a direct command to the Preference File ??? Thanks in advance.
Robert Lespérance
Model: iMac G5 1.6 MHZ - 2GB
AppleScript: 1.10.7
Browser: Safari 419.3
Operating System: Mac OS X (10.4)
Hello,
My previous message had no reply so I must understand that there is no other solution … When running the script, in the first dialog window, I encounter a problem. This is the first part of the script:
tell application "System Events" to tell process "SystemUIServer"
tell (get first menu bar item of menu bar 1 whose value of attribute "AXDescription" is "text input menu extra")
click
delay 0.1
click menu item "Canadian - CSAdot.rsrc" of menu 1
end tell
end tell
set selectedText to do shell script "pbpaste"
display dialog ¬
"Nom de votre mémo: " default answer "" default button "OK"
set titleText to text returned of result
My problem is that the field in the dialog window is distorted and I cannot enter any text. The text above the field is ok. Executed without the first TELL statement, the dialog window is normal and I can input my answer. I have picture of the resulting and normal dialog windows.
Anyone has a clue on this one ??? Thanks in advance.
Robert Lespérance
Model: iMac G5 1.6 MHZ - 2GB
AppleScript: 1.10.7
Browser: Safari 419.3
Operating System: Mac OS X (10.4)
Hi, Robert;
I don’t think the absence of a reply to your first query above meant that there was no solution - but it was Sunday night. I was getting the MacScripter.net article together, and the board is never very responsive on Sunday evening. Give it time. One problem often encountered in altering plists directly is that the application doesn’t refer to them again so you’re stuck with GUI scripting them so they’ll know the change has occurred. Several of the System Preferences are like that.
[Note: I edited your last two entries. You just select your script in the edit post box, and click the “AppleScript” button, the same way you would with the others. That allows the reader to download the file to their own Script Editor by simply clicking on the > Open this Scriptlet in your Editor: link at the head of that script.]
Hello Robert
You hare astonished by the absence of responce.
I am surprised that you use a code which is clearly described as unable to work in the thread whose link was given here.
When I tested it on my machoine (with an existing menu item name), it triggers the Sound menu, not the Layout one.
I met the problem, described it and got a clear responce signed “kai”.
Read it and you will understand.
On the other hand, I never saw a text input menu item whose name resemble to: “Canadian - CSAdot.rsrc”.
Are you using a customised layout file ?
Yvan KOENIG (from FRANCE lundi 27 novembre 2006 17:48:04)
[i]Thank you Adam,
I appreciate the editing and also the info regarding the “AppleScript” button. I will use it from now on.
Robert[/i]
Yves is correct. Your script works like this:
tell application "System Events" to tell process "SystemUIServer"
tell (get first menu bar item of menu bar 1 whose value of attribute "AXDescription" is "text input menu extra")
click
delay 0.1
click menu item "Canadian French - CSA" of menu 1 -- note change n item name
end tell
end tell
set selectedText to do shell script "pbpaste"
display dialog ¬
"Nom de votre mémo: " default answer "" default button "OK"
set titleText to text returned of result
This gets you back:
tell application "System Events" to tell process "SystemUIServer"
tell (get first menu bar item of menu bar 1 whose value of attribute "AXDescription" is "text input menu extra")
click
delay 0.1
click menu item "U.S." of menu 1
end tell
end tell
Bonjour Adam,
I don’t understand exactly what you and Yvan are both trying to tell me. I have read again the thread that you pointed me at and still maintain that the script that I used and submitted works. I find no difference between the last script that you sent me and the one that I use, except for the «note change n item name» that you added. I don’t understand either what that note is about.
I am not a pro at scripting. Also I am a French Canadian and maybe my English is misleading. Since I cannot record anymore a script in OS X like in OS 9, I mostly try to find already done scripts and copy/paste them to fit my use in a new script.
Yvan’s intervention #13 in your thread seems to be referring to a script that toggles between 2 or more keyboard layouts. Toggling is not what I am looking for. Toggling can be done very easily by giving a «keyboard shortcut» to the «select next keyboard layout (litteral french translation)» choice that already exists in the «keyboard shortcut» System Preference panel. I want the script to select a specific keyboard layout, not to toggle between tha active keyboard layout choices.
I have also tested the script in Yvan’s reply #12 of your thread and it also gives me the same result as the script submitted earlier. I repeat that the script I submited for debugging (or Yvan’s reply #12) does already what I want (I have tried it) except for:
(1) I would like better to have a script that executes in background, not showing all menu expansions, etc …
(2) my reply in this thread (#4) regarding the first dialog window (if you don’t understand what I mean I could send you pictures of the dialog window).
Hope this reply his more precise …
Robert Lespérance
Model: iMac G5 1.6 MHZ - 2GB
AppleScript: 1.10.7
Browser: Safari 419.3
Operating System: Mac OS X (10.4)
Hello
The main problem in your script is the use of the whose condition.
kai explained well that there is a bug in the system making it fail.
It doesn’t point to the correct menu.
On my machine, it doesn’t trigger the Layout menu but the Sound one which is not what is wished.
Yvan KOENIG (from FRANCE mardi 28 novembre 2006 06:43:24)
Hi.
Everyone seems to be talking at cross-purposes here.
Yvan’s insistence that ‘whose value of attribute “AXDescription” is “text input menu extra”’ doesn’t work is a red herring, because “ as was made clear in the other thread “ for some people it does work, including for myself and (apparently) for Robert. That part of the system is, nonetheless, unreliable.
Adam’s point is that there’s no keyboard layout in the OS X standard set with the name “Canadian - CSAdot.rsrc”. The change he made in message #8 accesses the Canadian layout that does come with the system.
Robert’s query (although he’s edited message #2 today) is:
He doesn’t want to see the menu opening and closing. Answer: there’s no way that can be avoided using the GUI Scripting method. The shell scripts at the end of the other thread may offer something here, but I haven’t had a chance to look at those yet.
After his script’s successfully selected the required keyboard, the text field in the following ‘display dialog’ isn’t rendered properly. Answer: I sometimes get this in other situations where the screen hasn’t redrawn properly. I normally just manually cover the affected spot with something else “ a window, say “ and then move the window out of the way to make the affected area redraw. But I’m not sure how I’d go about doing this by script, or why the dialog isn’t being drawn properly in the first place. One thing to try would be to put an activate command before the display dialog line, to ensure that the application displaying the dialog is frontmost.
Hello Nigel,
Thank you for helping. If you have any clue that can help me create a «background script» just suggest and I will try …
I tried to put a new window in front of the dialog window to force it to redraw, and it does not change. I also added an ACTIVATE line (anything else to put other than the ACTIVATE command ???) before the DISPLAY DIALOG line. I fell that the problem is less frequent but it still happens. I was trying to find out what were the conditions that were favorable to the distorted dialog window, but it seems to be random. Maybe not I will be vigilant …
All this trouble is because I still need to use a MAC OS 9 app for my accounting. By using this app I cannot upgrade to the OS X 3.0 version of the TYPEIT4ME utility (abbreviations expansion utility) that I use very frequently. TYPEIT4ME is installed as a keyboard layout that as to be selected in order to work. By using the 2.3 version of TYPEIT4ME, I get a bug that freezes my keyboard in the text field of certain OS X applications. When this occurs I only have to toggle from the TYPEIT4ME keyboard layout to my ordinary keyboard layout (BTW the CANADIAN - CSADOT.RSRC is a customized keyboard layout written by Tom Gewecke to replace the «,» by a «.» on the numeric keyboard with my french canadian international localisation).
Because my keyboard froze in the text input window of my application script, I wanted to select by script my CANADIAN - CSADOT.RSRC keyboard layout and select my TYPEIT4ME keyboard layout after the execution of my script.
This should make better sense of the reason of this thread. Thank you all for helping … It is very generous of you of concerning !!! :):):):):):)
Model: iMac G5 1.6 MHZ - 2GB
AppleScript: 1.10.7
Browser: Safari 419.3
Operating System: Mac OS X (10.4)
Hello Nigel
may you run this script on your system?
tell application "System Events" to tell process "SystemUIServer"
set ll to get value of attribute "AXDescription" of every menu bar item of menu bar 1
(* for me, it returns:
{"displays menu extra", "AppleScript menu extra", "text input menu extra", "volume menu extra", "clock menu extra"}
*)
end tell
On my machine the text input menu extra is the 3rd starting from the right of the list.
I’m quite sure that on your machine it is the 4th one.
This is why it works for you because the scripts using "whose value of attribute “AXDescription” always return the value “4”.
Add or remove an item to the set of menu and the script will fail.
Yvan KOENIG (from FRANCE mardi 28 novembre 2006 16:20:46)
Very interesting M. Koenig;
On my machine, this returns only one: “text input menu extra”, while currently in my menu bar there are FastScripts, CopyPaste, QuicKeys, gMail Notifier, Timbuktu, SOHO Flashnotes, SMARTReporter, MenuCalendarClock, Keyboards, and finally Spotlight.
Hello Yvan,
You are right … The «text input extra» is in the 4th position on my right menu bar … Putting it elsewhere returns this error message: «NSReceiverEvaluationScriptError: 4» …
Hi, Yvan.
The result I get from your test script with my normal configuration is:
That is, the Keyboard menu is the fifth item in my SystemUIServer menu bar. Before joining in the other thread, I also tested with the Classic and Displays menus enabled. These appeared to the left of my usual ones and thus became menu bar items 1 and 2 for SystemUIServer, making my Keyboard menu either the sixth or seventh menu bar item. In every case, the ‘whose value of attribute “AXDescription”’ filter correctly identified and opened the Keyboard menu. The filter therefore works for me in every case for this purpose, but not, apparently, for anyone else. However, as I described later on in the other thread, the same kind of filter doesn’t work for me in another script where I try to identify a particular menu item in a menu. I have to use a different filter form for that. This other form also works for me in identifying the Keyboard menu and “ as you report “ also works for you.
With regard to Adam’s response to your test script: if I activate FastScripts Lite and then run the script, I get exactly the same result as above “ that is, there’s no entry for FastScripts Lite in the returned list. The ability to click on the Keyboard menu using the disputed filter form is not affected.
There’s no doubt that that particular filter shouldn’t be relied upon, but it’s not reliably unreliable. It’s also not what’s been causing Robert’s problem.
I don’t know about FastScripts Lite, but there is no need to GUI program FastScripts - it’s scriptable.
Don’t add to the confusion.
:lol: