This tutorial requires one additional piece of software, wtype, which simulates keyboard activity. To install it, run the following command:
$ sudo apt -y install wtype
Next, we’ll tell your Raspberry Pi what to present in kiosk mode and how to present it. In this tutorial, we’ll display the Raspberry Pi home page and a page showing the time in London, switching between the two every few seconds.
To achieve this, we will edit .config/labwc/autostart, which is a configuration file used to automatically run programs when the Raspberry Pi OS desktop has loaded.
Edit the .config/labwc/autostart file in nano, a text editor, by running the following command:
$ nano .config/labwc/autostart
Add the following two lines:
chromium https://raspberrypi.com https://time.is/London --kiosk --noerrdialogs --disable-infobars --no-first-run --enable-features=OverlayScrollbar --start-maximized &
~/switchtab.sh
The first line opens the Chromium web browser in kiosk mode, with two tabs open: raspberrypi.com and time.is. The extra options alter kiosk mode in the following ways:
--noerrdialogs
-
Suppresses error messages
--disable-infobars
-
Disables notification infobars
--no-first-run
-
Skips the first-run setup experience that typically appears when launching for the first time
--enable-features=OverlayScrollbar
-
Scrollbars appear only when necessary and overlay content instead of using a dedicated scroll gutter
--start-maximized
-
Starts the browser in maximised full-screen mode
The second line executes a bash script (which we’ll create soon!) that automatically switches between the two tabs every ten seconds.
The ampersand (&) at the end of the first line is very important, as it ensures that both lines in the autostart file are run in parallel. If it were omitted, chromium would run, but the switchtab.sh script wouldn’t. (Technically, if the ampersand were missing, the switchtab.sh script would run after chromium has finished running — but since we’re running Chromium in kiosk mode, there’s no way to quit it!)
Press Ctrl+X, then Y, and finally Enter to save the edited file with nano.
Next, we’ll write the bash script that switches between the two tabs. Usually, the keyboard shortcut Ctrl+Tab cycles through open browser tabs. The script will use the program we installed, wtype, to simulate and automate these keystrokes. To create the script with nano, type:
Add the following to the file:
#!/bin/bash
# Find Chromium browser process ID
chromium_pid=$(pgrep chromium | head -1)
# Check if Chromium is running
while [[ -z $chromium_pid ]]; do
echo "Chromium browser is not running yet."
sleep 5
chromium_pid=$(pgrep chromium | head -1)
done
echo "Chromium browser process ID: $chromium_pid"
# Loop to send keyboard events
while true; do
# Send Ctrl+Tab using `wtype` command
wtype -M ctrl -P Tab -p Tab
sleep 10
done
This script first checks that the Chromium browser is running. If not, it waits five seconds before trying again (this gives Chromium enough time to launch before moving on). To toggle between the two tabs, the script uses wtype to simulate Ctrl+Tab every ten seconds.
Press Ctrl+X, then Y, and finally Enter to save the new file with nano. Mark the file as executable so that it can be run as a script:
$ chmod +x ~/switchtab.sh
Finally, reboot your Raspberry Pi:
Once your Raspberry Pi has rebooted, your display should be showing Chromium in kiosk mode, toggling between raspberrypi.com and time.is every ten seconds.
Depending on which websites your Raspberry Pi kiosk is displaying, you may want to temporarily plug a USB mouse into your Raspberry Pi so that you can dismiss any cookie pop-ups; the mouse can be unplugged again afterwards.