Phosh: Automatically disable the soft keyboard when the Pine64 keyboard shell is attached

If you’re using a Phosh-based distro that runs SystemD such as Mobian follow the guide here.

If you’re using a distro running OpenRC such as PostmarketOS Phosh follow the guide below:

As OpenRC can only run commands as root it was quite a challenge getting the environment variables right so gsettings could be run as the user but I got it figured out. :slight_smile:

Guide: Pinephone PostmarketOS w/ Phosh: Automatically disable the soft keyboard when the pine64 keyboard shell is attached and visa versa

Create the script:

touch /usr/local/bin/soft-kbd-override
chmod +x /usr/local/bin/soft-kbd-override
vi /usr/local/bin/soft-kbd-override

# Paste the following and save:

# Check interval is either the first parameter or every 10 seconds

# Attempt to get gnome-session pid till successful (phone startup)
while ! PID=$( pgrep gnome-sesson ); do
	sleep 3
export DBUS_SESSION_BUS_ADDRESS=$( xargs -0 -n 1 -a /proc/$PID/environ | grep '^DBUS_SESSION_BUS_ADDRESS=' | cut -d = -f2- )
sleep 5

while true; do
	cat /sys/class/power_supply/ip5xxx-battery/voltage_now 2>&1 >/dev/null && State='false' || State='true'

	if [ "$State" != "$PrevState" ]; then
		sudo \
				--user user \
				--set-home \
				--preserve-env \
				gsettings set org.gnome.desktop.a11y.applications screen-keyboard-enabled "$State" \
		&& PrevState=$State

	sleep "$CheckInterval"
# Test the script: (Ctrl+C to quit)

Create the service to run the script:

vi /etc/init.d/soft-kbd-override

# Paste the following and save:
name='Soft Keyboard Override'
description='Turns off the soft keyboard if a pine64 keyboard shell is detected'

# Run soft-kbd-override, there should be no errors or hanging
rc-service soft-kbd-override start

# Enable soft-kbd-override at startup at the default runlevel
rc-update add soft-kbd-override
1 Like