How to interact with zenity window and type some text inside it?
Change your zenity.sh
file with:
#!/usr/bin/python
zenity --forms --title="Question" \
--add-entry="Question" \
To:
#!/bin/bash
zenity --forms --title="Question" \
--add-entry="Question" \
You are not calling zenity
within a python script. You are calling it from a bash/shell command so your shebang (first line) must be #!/bin/bash
not #!/usr/bin/python
.
There are two requirements for xdotool
to work with your example:
- You should be running X11 and not Wayland.
- Your window created by
zenity
must be fully loaded before thexdotool
command is run.
To do this properly, you need to:
-
Load the window in the background ( with
&
) like so:zenity --forms --title="Question" --add-entry="Question" &
-
Give some time for the window to fully load ( with
sleep
) like so:sleep 1
-
Get your window ID by name like so:
window="$(xdotool search --name 'Question')"
-
Activate your window by ID ( stored in
$window
in step 3 above ) like so:xdotool windowactivate "$window"
-
Type the text in the window like so:
xdotool type 'some text'
So the final script will look like this:
#!/bin/bash
zenity --forms --title="Question" --add-entry="Question" &
sleep 1
window="$(xdotool search --name 'Question')"
xdotool windowactivate "$window"
xdotool type 'some text'