Wildcard with xdotool

The window id for the particular popup window is different each time, so this scripts often does not work.

Is there a way I could use a wildcard ?

Ex. xdotool key --window 1677*.* alt+F4

or go through all the relevant window IDs and filter what I need and discard the rest.

This gives me the correct window id.

xdotool search --name "Error" > Window_IDs.txt

I just need it to substitute the value it gets for the 16777491 xdotool key --window 16777491 alt+F4

#!/bin/bash
    # xdotool selectwindow This determines the window id or 2nd method
    # xdotool search --name "Error"
    #
    # Does not work because for some reason, the window id is different every time ?
    xdotool key --window 16777491 alt+F4
    # 
    #16777782
    #16777491
    #16778087
     #

I have provided ALL the info that I think pertains to this help request.

Not even close...

When you type in the command xdotool selectwindow , exactly what output do you get? (Please put the response to this question in CODE tags.)

When you type in the command xdotool search --name "Error" what output do you get? (Please put the response to this question in CODE tags.)

Out of the apparently tens of millions of window IDs xdotool creates, how are we supposed to know which one is the one you're looking for?

You did not pay very good attention to my post.

-- The window id for the particular popup window is different each time, so this scripts often does not work.

So your 2 question are not relevant.

Presumably, according to you, those tools give you output that contains the window IDs you want. If that isn't relevant to getting the results you want, I have no idea how we can help you.

If you're unwilling to show us sample output produced by those commands, we have no way of knowing what the format of the output produced by those commands might be.

If you are just going to dismiss our questions as an unreasonable waste of your time, then any attempt on our part to help you is a waste of our time.

I'm am sorry that I wasted your time trying to help you. I won't make that mistake again.

The commands produce simple numbers as shown in my post.

I would think you would test my xdotools command to learn how it works. Maybe I should not have assumed that?

#16777782 #16777491 #16778087

When I do my best, but am criticized, I start to wonder if someone is really tried to help me or just complain.

I do not have access to an Ubuntu system. I do not have access to, nor do I have any desire to load, learn how to run, nor run xdotool when, as far as I know, I have no need to have or use xdotool (especially when you tell me that it doesn't work well).

I do, however, have over 45 years of experience using UNIX tools to solve all sorts of problems and I would love to help you learn how to extract the window ID number out of the output from an xdotool selectwindow or xdotool search --name "Error" command if you'll explain to me where the window ID number that you want appears in the output produced by those commands. Telling me that they only produce "simple numbers" without knowing how many simple numbers each of them produces nor which of those simple numbers is the one you want nor what separates those simple numbers in the output of those commands doesn't really tell me anything I can use to help you.

If you would actually show me the exact output produced by one of those commands and explain to me which of the simple numbers output by one or both of those programs is the one and only window ID that you want to use in a subsequent xdotool key --window "window_ID" command on that instance of that system, I'd be happy to help you learn how to do that. But, if you think it is my duty to buy an Ubuntu system, load xdotool on it, learn how to run xdotool and then explain how xdotool works to you; I'm sorry, but that is not my job, is not in my budget, and is not something I have any interest in doing.

I nearly fell out of my chair when I read your statement statement above.

Why would you assume that?

When people, especially the ones here with decades of hands on UNIX and Linux experience, ask you for information, you should provide the info they ask for without hesitation.

Most people with decades of experience have realized that the vast majority of user errors and issues are general and they can be solved by looking at the input and output of the system, the log files and the operating environment.

We find that most users with problems do not even read their only system log files and we need to ask them to look at their own log files, believe it or not (shocking!?) . :slight_smile:

So, we don't need to install every tool and every operating system on the planet to help you, but you do need to provide the system information we request.

That's how it works.

So, please provide the information Don requested.

Thanks.

2 Likes
andy@7_~/Downloads$ xdotool selectwindow
16777957
andy@7_~/Downloads$ xdotool search --name "Error"
16777957

Let me try to relieve pressure a bit in this discussion. Nobody in here is criticized nor berated for no reason. Nobody is "just complain"ing. Asking for details is usually done for narrowing down open questions, targeting for a solution. Looking at the history of these forums, and esp. Don Cragun's contributions, you can see that helping requestors is THE MAIN FOCUS in here: data driven, solutions oriented.
In a recent post you complained being reminded of your >100 posts. The reason for the reminder is the expectation that with >100 posts someone knows WHAT to supply and how to supply it for maximum efficiency on both ends.

Very good objective. Still - please allow for clarifying questions.

Brilliant. Why not EXPLICITLY show those numbers AND their relation to the problem?

Yes, you are right, you shouldn't have. The best way to help has been proven to be asking questions and giving more or less generic hints leading the requestor in the right direction to find a solution on his/her own. Don't expect people in here to install more or less exotic tools to do your work for you.

Strongly discouraged. You almost certainly will target a wrong window, not every time, but over time.

You had a very similar, valid solution in your other thread which you dismissed. Difficult to understand

How do you know?

Which I would regard as a "usual behaviour".

Is that judgement up to you? Who wants help with a problem?

1 Like

Great. Now we know that two commands that you thought would provide you the window ID you wanted both return a single number AND even more encouraging, they both return the same number.

So, if you execute the commands:

windowID=$(xdotool selectwindow)
xdotool key --window $windowID alt+F4

does that do what you're trying to do?

Are there reasons why xdotool selectwindow might fail? If so, how would it react when it fails? And, if it fails does that mean that no window is running and you don't need to issue the second command???

1 Like

xdotool selectwindow activates a moveable box that you then position over the window to gets it id.

So it won't work in a script.

This is what happens if there is no window opened named No Window.

xdotool search --name "No Window"
andy@7_~/Downloads$ 
1 Like

OK, but how would that work at all in a script? If it doesn't work in a script at all then what is the point of trying to use it in a script? Or is it working differently in a script? Maybe by displaying a list of window IDs? And, if yes, will the output look like this:

xdotool selectwindow
16777957
16777958
16777959
16777960

or, rather, like this:

xdotool selectwindow
16777957 16777958 16777959 16777960

or completely different from that? That, btw., was the background of Don Craguns request to show the output. To answer all these (and maybe some additional) questions by providing a sample. I count 7 question marks i used above (two of them implied) - all of them unnecessary if you would have trusted Don to know what he does and treating his request as legitimate.

OK, please repeat this command for a non-existing window and add echo $? - in other words, please tell us the return code. If there is a non-zero return code in case no window is found (and a zero return code if there is a window found) logic could be based upon that.

I hope this helps.

bakunin

xdotool search works like this:

xdotool search --name "title-string"
16777957

The output is one ore more numbers(one per line), each representing a window-id or nothing if no window is found with the wanted specification. So one can use the solution presented with slight changes:

windowID=$(xdotool search --name "title-string")
xdotool key --window $windowID alt+F4

If necessary check if the number of results is what is expected.(Exact 1 result?)

Consult the manpage for xdotool for important and further details: Linux Manpages Online - man.cx manual pages

1 Like

--- Post updated at 11:20 AM ---

Since, the below mostly does not work, I think I am out of options.

I found another key tool, but I get a lot of errors when I try to compile it.

winid=$(xdotool search --name "Error")
#
xdotool key --window "${winid}" Return

I accept that I will have to enter my Enter key each time.

Here we go again: WHAT EXACTLY does not work? Is there an error messsage? No output where there should be one? Does the computer crash? How are we supposed to see what you see? Through our magic glass orbs, in between the lottery numbers for next week?

And if it does "mostly" not work: what does work? What doesn't? Is there a pattern? stomp has taken it on him to read the man page for the tool and even provided a link to it. Up to now you have done no such thing but complained about us being nosy.

If what sstomp says is true (and i have no reason to doubt it), then this:

xdotool search --name "title-string" | while read windowID ; do
     xdotool key --window "$windowID" "alt+F4"
done

should close all windows with the title "title-string". If it doesn't (or does something unwanted instead/in addition) you need to describe what it is. You also may want to prepend it with set -xv to see what it does during execution. Post the output if that if this is the case and you need help.

I hope this helps.

bakunin

I believe I already posted that alt+f4 ONLY closes the window.

Which is not what I need.

There are some things that are unsolvable.

I can live with that. :slight_smile:

Thanks for everyone's help. I do appreciate it.