Close popup window automatically

fixit7

Member
I am trying to find a way to automatically close a popup window by simulating a Return keypress.

I tried this, but no luck.

xdotool key --window 16777767 Return

Thanks
 


TechnoJunky

Well-Known Member
Are you talking about popups in your browser? Instead of automatically closing them, block them from opening in the first place. Firefox has lots of popup blocker extentions you can install. I'm sure Chrome does as well.
 

fixit7

Member
No, it is a popup caused by indicator applet complete has quit unexpectedly.

https://www.dropbox.com/s/eqfaf4zfncsuw24/Simulate_Enter_Keypress.png?dl=0

I am using Ubuntu Mate 18.04.

This works with run from cli, but not when added to my Startup Applications.

#!/bin/bash
#
# Automatically close that popup windows that occurs with every boot up
#
# xdotool selectwindow This determines the window id or 2nd method
# xdotool search --name "Error"
id=$(xdotool search --name "Error")

xdotool key --window $id alt+F4
 

JasKinasis

Well-Known Member
No, it is a popup caused by indicator applet complete has quit unexpectedly.

https://www.dropbox.com/s/eqfaf4zfncsuw24/Simulate_Enter_Keypress.png?dl=0

I am using Ubuntu Mate 18.04.

This works with run from cli, but not when added to my Startup Applications.

#!/bin/bash
#
# Automatically close that popup windows that occurs with every boot up
#
# xdotool selectwindow This determines the window id or 2nd method
# xdotool search --name "Error"
id=$(xdotool search --name "Error")

xdotool key --window $id alt+F4
Your script IS working - the only problem is - at startup it will only run once. And if the popup is not present when it is auto-ran - your script will have no effect, because it has nothing to act upon.

So what you could do is add an infinite loop and then keep looping and checking for it and killing it whenever it pops up. This would help if the dialog tends to pop up multiple times during your sessions.
If it only tends to pop up once, you'd do all of the above, but as soon as you have killed the window once, you can use "exit" to end the script.

Like this:
Code:
#!/usr/bin/env bash
# Periodically check for the existence 
# of an "Error" window
# and kill it if it exists
while true
do
    id=$(xdotool search --name "Error")
    if [ "$id" ]; then
        xdotool key --window "$id" alt+F4
        # uncomment the line below if the window only pops up once
        #exit
    fi
    id="" # reset id to blank
    # Sleep the thread for a while
    # Use whatever period you feel is required 
    sleep 60s
done
If you put the above script into your startup - it will run indefinitely and will check whether the popup window exists. If it does not exist, it will sleep for 60 seconds before reiterating through the loop and checking again.
If the window does exist - the script will close it, before sleeping for 60 seconds and checking again for the existence of the window.

That will fix the problem if the error pops up more than once during your session. Whenever an "Error" window pops up - the next time the script wakes up, it will kill it for you.

If the error message only tends to pop up once per session - uncomment the line that says "#exit", to read "exit". Then the above script will run until the dialog eventually pops up and will end as soon as the offending window has been killed.

Again, feel free to tweak the amount of time that the script sleeps for.

I haven't tested this BTW. But off the top of my head - it should work!
 

fixit7

Member
Your script works, but it closes popup. What I need is Return instead of alt+F4.

Unfortunately,
xdotool key --window "$id" Return
does not work.

I am wondering if xdotool has a bug.
 

JasKinasis

Well-Known Member
I haven't had a chance to fire up my Linux laptop and mess around with xdotool yet, but what about if you enclose the name of the keystroke in double quotes?
e.g.
Code:
xdotool key --window "$id" "Return"
Does that make any difference?
 

fixit7

Member
I tried it. I can not figure how how to create a code segment?

You specified the wrong number of args.
Usage: key [options] <keysequence> [keysequence ...]
--clearmodifiers - clear active keyboard modifiers during keystrokes
--delay DELAY - Use DELAY milliseconds between keystrokes
--repeat TIMES - How many times to repeat the key sequence
--repeat-delay DELAY - DELAY milliseconds between repetitions
--window WINDOW - send keystrokes to a specific window
Each keysequence can be any number of modifiers and keys, separated by plus (+)
For example: alt+r

Any letter or key symbol such as Shift_L, Return, Dollar, a, space are valid,
including those not currently available on your keyboard.

If no window is given, and there are windows in the stack, %1 is used. Otherwise
the currently-focused window is used
This command consumes all arguments after it, so you cannot chain
additional commands after it.
 

JasKinasis

Well-Known Member
Another option that might work is to send a different keybind to it.

For accessibility reasons, most buttons on dialogs have shortcut keys assigned to them.

The next time you see that error dialog, use your mouse to make sure it is the current/focused window.
Then press the alt key on your keyboard.
With any luck you should see some underscore characters appear underneath one of the letters in each of the text-labels on the buttons.

Whatever letter is highlighted, that is the keyboard shortcut for that button. So you could try sending alt+{letter} in your script instead.

At a guess, I would imagine that the shortcut for the "Delete" button would be: alt+d.
The "Don't reload" buttons shortcut would probably be: alt+o.
And the "Reload" buttons shortcut would probably be: alt+r

Either way, press the alt-key with the window in focus and see what keyboard shortcuts are set up. Then in your script, you could try using xdotool to send the keybind/shortcut for the button you want to activate instead of sending "Return".
 
Last edited:

fixit7

Member
You are right. alt+r does reload.

Does not work.
xdotool key --window "${winid}" alt+r

I even tried

#!/usr/bin/env bash
# Periodically check for the existence
# of an "Error" window
# and kill send alt + r to it
while true
do
id=$(xdotool search --name "Error")
if [ "$id" ]; then
xdotool key --window "$id" alt+r
# uncomment the line below if the window only pops up once
#exit
fi
id="" # reset id to blank
# Sleep the thread for a while
# Use whatever period you feel is required
sleep 15s
done

Alt+F4 is the only key command that works, but it closes the window. Makes me think that xdotool is buggy?
 

Members online


Top