'Linux script not executing properly after a reboot

I am using a raspberry pi4 with 32bit Raspbian to display some webpages. I have a script to open 2 webpages, one on each monitor. The end of the script selects one of the pages and enters in login credentials. The script works great and I have it working with systemctl to auto start on reboot. The problem is the script doesn't always select the window after a reboot of my pi. It works 50% of the time. Which I believe is just which page happens to open first. Sometimes the cursor is left on the correct page. This happens whether I am using the systemctl or not.

The line it seems to ignore is:

xdotool search --name 'Login'>xdotool windowactivate

Troubleshooting that I did:

  • Waiting a long time after rebooting - This didn't work
  • Changed windowactivate to windowfocus - This made no difference
  • Removing the --kiosk flag - This didn't work
  • Closing the windows and running the script again - Works every subsequent time
  • Opening a browser and closing it after reboot then running script - Works every subsequent time

This led me to the next step which was to add a sleep in between opening the browsers. My hope was that once the second browser opened it would just be left as the active browser. Unfortunately this solidified my conclusion that the script isn't executing properly after a reboot.

After adding the sleep, the browsers open simultaneously after a reboot ignoring the sleep command. However, if I close the browsers and run the script again the sleep command works and 1 browser opens then the other one after the sleep.

  • Then I tried adding at the beginning of the script to open a browser and then close it and then continuing the script -This didn't work.

Almost as if ignoring the opening and closing of the browser? I tried buffering the 2 commands with sleep but it ignored those as well.

The script works 100% of the time either the second time it is ran or after opening and closing a browser.

Below is my script.

#!/bin/bash
xset s noblank
xset s off
xset -dpms

unclutter -idle 0.5 -root &

sed -i 's/"exited_cleanly":false/"exited_cleanly":true/' /home/pi/.config/chromium/Default/Preferences
sed -i 's/"exit_type":"Crashed"/"exit_type":"Normal"/' /home/pi/.config/chromium/Default/Preferences
rm -rf ~/.config/chromium/Singleton*

/usr/bin/chromium-browser --new-window --noerrdialogs --disable-infobars --kiosk --user-data-dir="/tmp/1" --window-position=0,0 'http://ExampleDisplay.com' &
/usr/bin/chromium-browser --new-window --noerrdialogs --disable-infobars --kiosk --user-data-dir="/tmp/2" --window-position=2500,0 'http://ExampleLogin.com' &

sleep 7
xdotool search --name 'Login'>xdotool windowactivate
sleep 2.5
xdotool type 'TEST' # CHANGE THIS FOR DIFFERENT LOGIN
sleep .2
xdotool key 'Tab'
sleep .2
xdotool type 'TEST' # CHANGE THIS FOR DIFFERENT LOGIN
sleep .2
xdotool key 'Return'
sleep 4
xdotool type 'TESTORG' # CHANGE THIS FOR DIFFERENT ORGANIZATION
sleep .2
xdotool key 'Tab'
sleep .2
xdotool key 'Tab'
sleep .2
xdotool key 'Tab'
sleep .2
xdotool type 'TESTSTATION' # CHANGE THIS FOR DIFFERENT STATION
sleep .2
xdotool key 'Return'

To rule out other parts of the script I tried boiling it down to the very basic issue of opening the browsers one after the other with this script. This had the same issue, after a reboot it opens both browsers ignoring the sleep function. Then if ran again it works.

#!/bin/bash
/usr/bin/chromium-browser --new-window --noerrdialogs --disable-infobars --kiosk --user-data dir="/tmp/1" --window-position=0,0 'http://ExampleDisplay.com' &
sleep 5
/usr/bin/chromium-browser --new-window --noerrdialogs --disable-infobars --kiosk --user-data-dir="/tmp/2" --window-position=2500,0 'http://ExampleLogin.com' &

Lastly, here is my systemctl (this shouldn't be needed because it happens regardless of using the systemctl, but just in case)

[Unit]
Description=Chromium Kiosk
Wants=graphical.target
After=graphical.target

[Service]
Environment=DISPLAY=:0.0
Environment=XAUTHORITY=/home/pi/.Xauthority
Type=forking
ExecStart=/bin/bash /home/pi/kiosk1.sh
Restart=on-abort
User=pi
Group=pi

[Install]
WantedBy=graphical.target

As a side note, I tried an alternative solution using a python script for the opening of the browsers using the multibrowse.py script from https://github.com/foxxyz/multibrowse and had the same issues even when adding the sleep calls between the browsers in the python script.

Thanks for any help in advance!



Solution 1:[1]

I don't use xdotool, but suspect you want:

xdotool windowactivate $(xdotool search --name 'Login')

Hopefully that means you will activate the window whose name is 'Login', which the xdotool search ... found.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mark Setchell