Score:3

How to enable accessibility for GTK applications running as root?

gf flag

I have a graphical application on Ubuntu 20.04 that is run with pkexec to properly get necessary root access. Many users will need the on-screen keyboard for this app, however I noticed that GTK apps will only display the OSK when not run as root. (sudo gedit doesn't work either)

How can I use the OSK when running a gtk app as root through pkexec?
I'm aware of onboard, but would prefer to inherit the Gnome OSK if possible.

EDIT: I ended up using a script that first checks if the user's GNOME OSK is enabled, then launches Onboard for the duration of the program (passed as arg):

/usr/bin/my-program $(pkexec --user myUser gsettings get org.gnome.desktop.a11y.applications screen-keyboard-enabled)

I tried sudo -E and there is no pkexec equivalent. Couldn't get it working.

kanehekili avatar
zw flag
Looks to me like a [xy-problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem): Why do you need to run an application as root in the first place?
Mdurks avatar
gf flag
It modifies network + system files. I'm aware it's best to avoid running graphical apps as root if possible, but I understand pkexec to be an accepted method to do so.
petep avatar
in flag
Try "sudo -E ". To run as root your app.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.