Catégories
Programmation Terminal

Web page in kiosk mode

Bash script to run a simple HTTP server with Python and open Chrome in kiosk mode, with some flags to allow access to serial port or automatic download. Written and tested on macOS.

Install

Save the following bash script to a file with .command extension, for example kiosk.command.

#!/bin/bash

# This bash script starts a python http server and then launches chrome in kiosk mode
# The http server is killed after chrome is closed
#
# Place the script in the folder where the html files are located
# Add execute permissions to the script with the following command in the terminal:
#
#   chmod +x start.command
# 
# Then double click the script to start the server and launch chrome in kiosk mode
# To stop the server and chrome, close the chrome window
#
# Note: This script is for Mac OS X. It may need to be modified for other operating systems
#
# Note: The script assumes that python3 is installed. If python3 is not installed, 
# it can be installed from https://www.python.org/downloads/
# 
# Note: The script assumes that the python http server is installed. If the python http server
# is not installed, it can be installed with the following command:
# 
#   pip install http.server
# 
# Note: The script assumes that the python http server is run with python3. If python3 is not 
# the default python version, the command may need to be changed to python or python3.7 or similar
#
# Written by Pierre Rossel on 2024-05-15


# change to the directory where the script is located
cd "$(dirname "$0")"

# Run an http server in the background
python3 -m http.server 5500 & 

# remember the PID of the http server to kill it later
http_server_pid=$!

# launch chrome in kiosk mode in the foreground
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome \
--chrome-frame \
--kiosk \
--disable-download-warning \
--autoplay-policy=no-user-gesture-required "http://localhost:5500"

# kill the http server after chrome is closed
kill $http_server_pid

echo done

Add execute permission (in the terminal):

chmod +x kiosk.command

Install python and http.server module. See comments in script.

Execute

Double-click from the finder to test.

Quit chrome to stop the server.

Kill the script in the terminal to exit chrome and stop the server.

Automatically run on boot

See https://support.apple.com/en-us/guide/mac-help/mh15189/mac to find how to automatically run the script on boot.

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Ce site utilise Akismet pour réduire les indésirables. En savoir plus sur comment les données de vos commentaires sont utilisées.