本教程需要额外安装一个软件,wtype, which simulates keyboard activity. To install it, run the following command:
接下来,我们将配置树莓派在亭式模式下显示的内容及显示方式。在本教程中,我们将交替显示树莓派主页和伦敦时间页面,每隔几秒切换一次。
为此,我们需要编辑.config/labwc/autostart, which is a configuration file used to automatically run programs when the Raspberry Pi OS desktop has loaded.
编辑.config/labwc/autostart file in nano, a text editor, by running the following command:
$ 纳米.config/labwc/autostart
添加以下两行:
chromium https://raspberrypi.com https://time.is/London--kiosk--noerrdialogs--disable-infobars--不-first-run--enable-features=OverlayScrollbar--start-maximized&
~/switchtab.sh
第一行代码以 kiosk 模式打开 Chromium 网页浏览器,并预先打开两个标签页:raspberrypi.com and time.is. The extra options alter kiosk mode in the following ways:
--noerrdialogs
-
抑制错误消息
--disable-infobars
-
禁用通知信息栏
--no-first-run
-
跳过首次运行时通常出现的初始设置界面
--enable-features=OverlayScrollbar
-
滚动条仅在必要时显示,并覆盖内容,而不使用独立的滚动边距
--start-maximized
-
以全屏最大化模式启动浏览器
第二行代码执行一个 bash 脚本(我们很快就会创建!),该脚本每十秒自动在两个标签页之间切换。
符号 &(&) at the end of the first line is very important, as it ensures that 两者中的行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 之后 chromium has finished running — but since we’re running Chromium in kiosk mode, there’s no way to quit it!)
按下Ctrl+X,然后Y,最后按输入用于将编辑后的文件保存为nano.
Next, we’ll write the bash script that switches between the two tabs. Usually, the keyboard shortcut Ctrl+Tab循环切换已打开的浏览器标签页。该脚本将使用我们安装的程序,wtype, to simulate and automate these keystrokes. To create the script with nano, type:
将以下内容添加到文件中:
#!/bin/bash
chromium_pid=$(pgrep chromium| head-1)
while [[-z$chromium_pid ]]; do
echo “Chromium 浏览器尚未运行。”
睡眠 5
chromium_pid=$(pgrep chromium| head-1)
完成
echo “Chromium 浏览器进程 ID:$chromium_pid"
while 真; do
wtype -M ctrl -P Tab -p Tab睡眠 10
完成
该脚本首先检查 Chromium 浏览器是否正在运行。如果未运行,则等待五秒钟后再重试(这样可确保 Chromium 有足够的时间启动,然后再继续执行)。为了在两个标签页之间切换,脚本使用wtype to simulate Ctrl+Tab每十秒一次。
按下Ctrl+X,然后Y,最后按输入以保存新文件nano. Mark the file as executable so that it can be run as a script:
$ 输入以下命令以使该文件具有可执行权限:+x ~/switchtab.sh
最后,重启您的树莓派:
树莓派重启后,您的显示器应会以展台模式显示 Chromium,并在以下选项之间切换:raspberrypi.com and time.is every ten seconds.
根据您的树莓派展台所显示的网站不同,您可能需要暂时将 USB 鼠标插入树莓派,以便关闭任何 Cookie 弹出窗口;之后可以再次拔下鼠标。