Quickly changing input methods via an applescript
Hello all. I'm relatively new to Mac ownership, but I'm jumping in trying to customize some things.
This started in the following thread:
http://discussions.apple.com/thread.jspa?threadID=1332310&tstart=0
What I'm trying to do:
With several input methods active, switching between them by the default MacOS allowed methods gets to be rather tedious. For example, Japanese, where one may easily find themselves switching between 3 input methods: US or Romaji, Hiragana, and Katakana. I much prefer the one-hotkey-per-input-method approach of some other operating systems. Plus, I'd really like to use speech and just tell my mac "switch to katakana" or "switch to hiragana." If it were just those two, then the default hotkeys would work for such a thing, or even configuring Kotoeri to use CAPS to switch between them would suffice. Anyway, enough about WHY I want to do this.
In the thread above, I was pointed to this thread on MacScripter: http://bbs.applescript.net/viewtopic.php?id=18620&p=1
With a minor modification for Leopard (changing "text input menu extra" to "text input"), the script works. But it is slow. I then spent a little time tweaking and seem to have gotten something more efficient:
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" 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
click menu item "Katakana"
end tell
end tell
end if -- j > 0
end tell -- to process and System Events
This is acceptably fast when running from within Script Editor, but when saved as an application takes anywhere from 3 to 5 seconds to switch input methods. I might as well mouse it or tab through multiple selections with the standard hotkeys at that rate.
Is this normal?
Does anyone know of a simpler way to accomplish this than UI scripting? Apparantly in OS9 it was as simple as set keyboard layout to "Katakana" or some such. Does anyone know where I might look to find the magical setting that can change it directly?
I'm sure the time issue has to do with (a) starting the interpreter and (b) all the parsing of the menu properties to find the right menu, then clicking it to get access. I'm sure it would go a lot faster if there was a way to go directly to the menu and not have to click it. Even better would just be some system property that could be directly set.
Thanks for any help you could give me!
This started in the following thread:
http://discussions.apple.com/thread.jspa?threadID=1332310&tstart=0
What I'm trying to do:
With several input methods active, switching between them by the default MacOS allowed methods gets to be rather tedious. For example, Japanese, where one may easily find themselves switching between 3 input methods: US or Romaji, Hiragana, and Katakana. I much prefer the one-hotkey-per-input-method approach of some other operating systems. Plus, I'd really like to use speech and just tell my mac "switch to katakana" or "switch to hiragana." If it were just those two, then the default hotkeys would work for such a thing, or even configuring Kotoeri to use CAPS to switch between them would suffice. Anyway, enough about WHY I want to do this.
In the thread above, I was pointed to this thread on MacScripter: http://bbs.applescript.net/viewtopic.php?id=18620&p=1
With a minor modification for Leopard (changing "text input menu extra" to "text input"), the script works. But it is slow. I then spent a little time tweaking and seem to have gotten something more efficient:
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" 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
click menu item "Katakana"
end tell
end tell
end if -- j > 0
end tell -- to process and System Events
This is acceptably fast when running from within Script Editor, but when saved as an application takes anywhere from 3 to 5 seconds to switch input methods. I might as well mouse it or tab through multiple selections with the standard hotkeys at that rate.
Is this normal?
Does anyone know of a simpler way to accomplish this than UI scripting? Apparantly in OS9 it was as simple as set keyboard layout to "Katakana" or some such. Does anyone know where I might look to find the magical setting that can change it directly?
I'm sure the time issue has to do with (a) starting the interpreter and (b) all the parsing of the menu properties to find the right menu, then clicking it to get access. I'm sure it would go a lot faster if there was a way to go directly to the menu and not have to click it. Even better would just be some system property that could be directly set.
Thanks for any help you could give me!
iMac core2duo, Mac OS X (10.5.1)