-3

I can't understand why this line won't work

firefox & xdotool search --name firefox > file

xdotool search --name firefox is supposed to find a window whose title contains word "firefox" and returns a number. I need it redirected to a file to use it later. Point is,

chromium-browser & xdotool search --name firefox > file

and

firefox & xdotool search --name chromium > file 

work perfectly, problem must be either time needed to map a window (but putting a sleep 10 inbetween didn't solve) or the task can't be done in the same shell. I need the second command to run right after (or some seconds after) the first one starts, not when it's done.

The second command will only produce output if I launch it after the other from the same terminal shell or in another shell, but not together like in the mentioned example. I tried with disown and nohup and I tried with a second & at the end, didn't get any result

Any suggestion?

  • 1
    Why are you trying to execute the output of xdotool while at the same time redirecting it to a file? Those command substitutions would always be empty... Why are you using command substitutions here at all? Your issue is probably a timing issue as gcalculator would probably not have had time to map a window before xdotool is launched, but I'm not sure as I don't know what either command does. – Kusalananda Aug 14 '18 at 16:40
  • As you probably noticed I'm not very good at this but, as I said, I didn't find the answer I was looking for in online tutorials and other forums or questions. – Lupccs Aug 14 '18 at 20:57
  • @Kusalananda command subsitution was useless, indeed. gcalculator is a simple gui calculator; xdotool search --name galculator finds a window whose title contains word "galculator" and returns a number. I need it redirected to a file to use it later. Point is, gedit & xdotool search --name galculator > file, and galculator & xdotool search --name gedit > file work perfectly, issue must be either time needed to map a window (but putting a sleep 10 inbetween didn't solve) or it can't be done in the same shell. I need 2nd command to run right after the first starts, not when it's done. – Lupccs Aug 14 '18 at 21:21
0

I only needed to add a --sync option from the xdotool manual page

--sync

Block until there are results. This is useful when you are launching an application want want to wait until the application window is visible.

Which makes the correct command

application & xdotool search --sync --name string_contained_in_the_window_title > file

like, in my case

firefox & xdotool search --sync --name firefox > firefox.txt
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.