a-shell
a-shell copied to clipboard
Feature idea: commands to hide or show onscreen keyboard
Hi! A simple command to hide a screen keyboard would be useful to have. Sometimes a script runs in terminal and does not need any more keyboard attention. The keyboard obsures a great part of the screen and hiding it every time adds more steps in workflow. Something like hideKeyboard and showKeyboard would suffice. Thank you
A messy, one-line solution
This works for me (for hiding the onscreen keyboard):
jsi -wc 'if (!window.b) { window.b = document.createElement("button"); document.body.appendChild(b); } b.focus()'
jsi
stands for "Javascript Interpreter" and can be used to modify a-Shell
's GUI when given the w
flag. -c
tells it to evaluate the next argument, instead of entering interactive mode. See man jsi
.
The script above creates a button and focuses it, which pulls focus away from the terminal.
I hope this helps you!
Alternate (probably better) solution
Another, perhaps better, option could be to add a python file to your ~/Documents/bin
directory called hideKeyboard
. To do this,
Create the bin
directory
$ mkdir ~/Documents/bin
$ cd ~/Documents/bin
Create a new python file in the bin
directory and make it executable
$ cd ~/Documents/bin
$ touch hideKeyboard
$ chmod u+x
$ echo '#!/bin/python' > hideKeyboard
The last two lines tell a-Shell
that (1) the file is executable and (2) that it should be run with python
.
Have the python
file run a script in `a-Shell`'s GUI with os.system
This can be done with the following (i.e. this is what ~/Documents/bin/hideKeyboard
should look like):
#!/bin/python
# To run a javascript file in the terminal GUI, we
# can use the jsc command.
EXEC_JS_COMMAND = 'jsc --in-window'
# We'll make this script in the next step.
PATH_TO_JS_SCRIPT = '~/Documents/js/hideKeyboard.js'
import os
# Run the command!
os.system('%s %s' % (EXEC_JS_COMMAND, PATH_TO_JS_SCRIPT))
Create a new .js
file called hideKeyboard.js
. I put mine in ~/Documents/js/
.
$ mkdir ~/Documents/js/
$ touch ~/Documents/js/hideKeyboard.js
Because when button
elements have focus, the virtual keyboard is hidden, have hideKeyboard.js
create a button, add it to the document, and focus it.
Put the following in hideKeyboard.js
:
// If we've already created a button for this purpose,
// it doesn't make sense to add another to the document!
// We can just re-use the previous.
if (!window.hide_kbd_button) {
window.hide_kbd_button = document.createElement('button');
document.body.appendChild(window.hide_kbd_button);
}
// Have the keyboard button steal focus.
window.hide_kbd_button.focus();
You should now be able to type hideKeyboard
in the terminal to hide the virtual keyboard!
Note that this script, at present, could be annoying if using a physical keyboard -- it defocuses the terminal UI, requiring a tap on the screen. It could be modified to refocus the terminal UI on keyboard input, though.
A messy, one-line solution
This works for me (for hiding the onscreen keyboard):
jsi -wc 'if (!window.b) { window.b = document.createElement("button"); document.body.appendChild(b); } b.focus()'
jsi
stands for "Javascript Interpreter" and can be used to modifya-Shell
's GUI when given thew
flag.-c
tells it to evaluate the next argument, instead of entering interactive mode. Seeman jsi
.The script above creates a button and focuses it, which pulls focus away from the terminal.
I hope this helps you!
thank you i tried this and it does hide the keyboard when ran alone
but when i use it as part of my shortcut, a-shell does nothing with that combination of commands, which i assume happens when it thinks something is wrong with my code

i will keep trying things to figure out how to make it work
Does this (more minimalistic example) work for you?
thank you
tried this, nothing happened this time either
The minimalistic example works for me (on an iPhone with iOS 15.1). Maybe it has to do with the split screen?
What happens if you add a sleep 1
as a new command before the jsi -wc ...
command?
Edit: It's strange that nothing is being printed at all. Try closing a-Shell and re-running the minimalistic shortcut.
I can reproduce the issue described above if I
- Open a-Shell
- Open Shortcuts
- Run the minimalistic shortcut
...but not if I
- Make sure a-Shell is not open
- Open Shortcuts
- Run the minimalistic shortcut.
I think this is a bug -- I'm reporting the issue.
yes - this is exactly as you mentioned, i tried on my iphone and it worked for the first time. then it would not. so i closed the app and removed the open app action and it worked on both devices.
I think this is a bug -- I'm reporting the issue.
thank you. not only did your code make my workflow easier, you also found a cause of a different bug, all in just a few minutes
Hi, I think I have a hideKeyboard command working, but showKeyboard is not, currently, working. Since clicking on the window does bring the keyboard, I am not certain whether it is worth having the showKeyboard command (and also not certain whether I can make it work, anyway).
Thank you, that's perfect. Hide Keyboard was my main wish and a reason for my post, so that is sufficient enough for me.
The new TestFlight version ( https://testflight.apple.com/join/WUdKe3f4 ) has two different ways to hide the keyboard:
- manual: long press on the toolbar (works both on phones and iPads)
- automatic:
hideKeyboard
command.
In both cases, clicking on the terminal window will bring back the keyboard, but scrolling around will not (so people with small screens can dismiss the keyboard, read the output of the command, then bring it back). Please let me know if this works for you.
Hi, this is fantastic. I tried it both with my manual commands and in my workflows using shortcuts, and it works great. Thank you