Sunday, April 28, 2024
 Popular · Latest · Hot · Upcoming
3
rated 0 times [  3] [ 0]  / answers: 1 / hits: 1231  / 2 Years ago, fri, october 28, 2022, 9:24:59

I have python code :


import subprocess
subprocess.call(['sh', './zenity.sh'])

and zenity.sh file which is


#!/usr/bin/python

zenity --forms --title="Question"
--add-entry="Question"

Running it opens window with field to type some text.


I want to type some text inside this zenity window using for e.g. xdotool I tried to use


subprocess.call(["xdotool", "type", "some text"])

not working


then I created another .sh


#!/bin/bash


xdotool search --class zenity windowfocus type 'some text'

also not working


Any ideas?


More From » 18.04

 Answers
3

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 the xdotool command is run.


To do this properly, you need to:



  1. Load the window in the background ( with & ) like so:


    zenity --forms --title="Question" --add-entry="Question" &


  2. Give some time for the window to fully load ( with sleep ) like so:


    sleep 1


  3. Get your window ID by name like so:


    window="$(xdotool search --name 'Question')"


  4. Activate your window by ID ( stored in $window in step 3 above ) like so:


    xdotool windowactivate "$window"


  5. 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'

[#1593] Saturday, October 29, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
adedes

Total Points: 454
Total Questions: 114
Total Answers: 111

Location: Turks and Caicos Islands
Member since Fri, May 8, 2020
4 Years ago
;