I try to automate some repetitive tasks with xdotool. In one task I want to automatically save a website to a file. While printing on Firefox there is a progress bar which looks like this:

enter image description here

I want to start a new task when the printing window has been closed (it closes automatically after saving the file). My current workaround is to use something like sleep 10 to prevent the next task from beginning to early. How can I get the event that the printing window has been closed?

(I am a Linux Mint user.)

Bash script

# Get window id (Firefox)
FIREFOX_ID=$(xdotool search --name "Mozilla Firefox" | head -n1)
# Activate window (Firefox)
xdotool windowactivate "$FIREFOX_ID"
# Open print dialog
xdotool key "ctrl+p"
# Get window id (print dialog)
DIALOG_ID=$(xdotool search --name "Print") # Change name to your language
# Activate window (print dialog)
xdotool windowactivate "$DIALOG_ID"
# Click "Print" button
xdotool mousemove 1240 790 click 1 # Change coordinates to yours
  • 1
    Do you know of the wait command? Please also add some code example.
    – FelixJN
    Jan 13, 2021 at 12:16
  • @Fiximan I added some code. No, I don't know wait. Jan 13, 2021 at 12:22

1 Answer 1


I think you could just check for the "Printing" window. Take your code as above, and let's focus on the moment you click print:

# Click "Print" button
xdotool mousemove 1240 790 click 1 # Change coordinates to yours

After that, you will have a "Printing" ("Drucken") progress box appear. Let's just check for its existence before moving on:

#sleep 1 second to allow printing to start - a pure safety measure
sleep 1
#check for printing progress window until failed
while (xdotool search --name "Printing") ; do
  sleep 0.1
<next command>

I.e. as long as there is a "printing" dialogue, do the while-loop will run and block the next command.

Regarding the wait command:

This does not apply here, as xdotool activates processes outside the shell script. Nevertheless it is simply used to ensure that a process is being waited for to finish:

 do_some_command & wait
  • Wouldn't it be possible to get the process id of the active window with xdotool getactivewindow getwindowpid and then activate the ẁait command? (BTW: Your code works like charm! Thank you!) Jan 13, 2021 at 13:02
  • Actually your codes print every 0.1 seconds the output of the command xdotool search --name "Printing" to the console. To prevent this I use xdotool search --name "Printing" > /dev/null 2>&1 instead. Jan 13, 2021 at 13:23
  • 1
    @Sr.Schneider wait is limited to the current shell, so no, you could not wait for some process not part of the script. Yes, dumping the output is a good point.
    – FelixJN
    Jan 13, 2021 at 22:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .