|
|
#1 |
|
Prospect
Join Date: Apr 2005
Posts: 2
|
Change keyboard Applescript
Hi there,
Anyone knows how to change the keyboard layout using Applescript or Realbasic, On OS X? Any help will be apreciated.
|
|
|
|
|
|
#2 | |||||||||||||||||||||||
|
Prospect
Join Date: Mar 2006
Posts: 3
|
I need to switch between "Dvorak - Qwerty" and "Swiss German" a lot. Key codes and keystrokes don't work on my setup - my code solves that too Some times the layout doesn't change after the first click (scripted and by mouse) so this code only carries on after the layout has been changed -> ! could result in an infinite loop ! Code:
set theMenuName to "text input menu extra" tell application "System Events" tell application process "SystemUIServer" set menuBar to menu bar 1 --> causes trouble: menu bar items of menuBar whose value of attribute "AXDescription" is theMenuName --set trk to get value of attribute "AXDescription" of every menu bar item of menu bar 1 --set trk to value of attribute "AXDescription" of every menu bar item of menu bar 1 set menuBarItemsList to value of attribute "AXDescription" of menu bar items of menuBar log "|tBC" set theMenuNum to my positionOfAinListB(theMenuName, value of attribute "AXDescription" of menuBar's menu bar items) if -1 ? theMenuNum then set theMenu to menuBar's menu bar item theMenuNum tell theMenu --the icon on menu bar repeat 3 times -- just handy for debugging -- can only get menu items if menu dropped if not selected then click set namesOfMenuItems to name of menu items of menu 1 if "Dvorak - Qwerty " = value then if "Swiss German" is in b then my clickThisMenuItem(theMenu, "Swiss G", first menu item of menu 1 whose name is "Swiss German") else beep log "Didn't find Swiss" end if else if "Swiss German" = value then -- this loop is ugly way to find out which item's name begins with to avoid having to deal with symbols and keyboard shortcuts -- can't use the positionOfAinListB routine because of the name's last character repeat with i from 1 to count (menu items of menu 1) set c to menu item i of menu 1 if c's name begins with "Dvorak -" then exit repeat end repeat my clickThisMenuItem(theMenu, "Dvorak -", c) end if log "loop" end repeat end tell end if end tell end tell to clickThisMenuItem(theMenu, menuItemNameStart, Menuitem) -- using timeout tell application "System Events" tell application process "SystemUIServer" tell theMenu repeat until value begins with menuItemNameStart if not selected then click tell Menuitem to click delay 0.2 end repeat end tell end tell end tell --end end clickThisMenuItem to positionOfAinListB(itemA, listB) if (itemA is in listB) then repeat with i from (count listB) to 1 by -1 if itemA = listB's item i then return i end repeat else return -1 end if end positionOfAinListB |
|||||||||||||||||||||||
|
|
|
|
|
#3 | |||||||||||||||||||
|
All Star
Join Date: May 2004
Location: london on ca
Posts: 930
|
If you are only switching between two, you could also enable the "System Preferences" > "Keyboard & Mouse" > "Input Menu" > "Select the previous input source" option. For years (at least as far back as the System 7 era), the keyboard shortcut was ?Spacebar although that was unceremoniously be co-opted by Spotlight in 10.4, resulting in a conflict. At least it remains customizable... |
|||||||||||||||||||
|
|
|
|
|
#4 | |||||||||||||||||||||||
|
Prospect
Join Date: Mar 2006
Posts: 3
|
I can't use keystrokes or key codes so that's not an option on my system. On a system where AS can successfully initiate keystrokes, I would agree. |
|||||||||||||||||||||||
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|