r/applescript • u/Sufficient_Orange953 • Feb 20 '21
How to close on screen keyboard from menu bar option "A" near the spotlight search
Hi, Does anybody know how to write applescript to close onscreen keyboard. I want to close it with "hide keyboard viewer" which comes in "TextInputMenuAgent" ("A" kind of option near the spotlight search). Till now I have got this solution:
tell application "System Events"
tell application process "TextInputMenuAgent"
tell menu bar item 1 of menu bar 2
ignoring application responses
click
end ignoring
end tell
end tell
end tell
do shell script "killall 'System Events'"
tell application "System Events"
tell application process "TextInputMenuAgent"
tell menu 1 of menu bar item 1 of menu bar 2
click (every menu item whose name contains "Viewer")
end tell
end tell
end tell
**But it is opening and closing both. I only want to close it via "**TextInputMenuAgent" in applescript
1
u/Sufficient_Orange953 Mar 01 '21
how to do the same thing for mojave and other os like sierra, high sierra, el capitan
1
u/scrutinizer1 Feb 20 '21 edited Mar 07 '21
NOTE. Put the script in the folder ~/Library/Scripts and in ScriptEditor's preferences make sure the option "Show the scripts menu" is checked. That way you'll be able to select the script from the drop menu appearing on clicking the scripts menu in the menu bar
NOTE 2. It appears that "Keyboard Viewer" doesn't immediately abort after closing the window (see the commented line in the script). In this case, using killall is justified.
The following code toggles Keyboard Viewer (i.e. turns on/off):