Auto-Rotation on KDE Plasma ( Wayland ) – Lenovo ThinkPad X1 Tablet Gen 3

CONTEXT -------- Debian 13 (Trixie) + KDE Plasma 5.27 on Wayland.   Lenovo ThinkPad X1 Tablet Gen 3 (QHD 3000×2000, i7-8550U).   iio-sensor-proxy detects the accelerometer but doesn’t publish orientation on DBus.   Solution: use raw accelerometer values and rotate via kscreen-doctor (KDE’s Wayland tool). REQUIREMENTS ------------- sudo apt install kscreen   Accelerometer visible at /sys/bus/iio/devices/iio:device*/in_accel_x_raw FINAL SCRIPT — ~/.local/bin/autorotate-wayland.sh ------------------------------------------------- #!/usr/bin/env bash # Auto-rotate for KDE Plasma (Wayland) – ThinkPad X1 Tablet Gen 3 # Reads raw accelerometer data and rotates screen via kscreen-doctor. # Touch/pen mapping handled automatically by Wayland. # Create ~/.config/autorotate.lock to disable rotation temporarily. OUTPUT_ID="output.1"                                 # from `kscr...

Scripting essential

Bash built-in commands GNU manual:
https://www.gnu.org/software/bash/manual/html_node/Bash-Builtins.html

Built-in, Special built-in and POSIX Inherited command list:
https://www.computerhope.com/unix/bash/index.htm


Basic syntax and special characters


Character Description
#                 Used to add a comment, except when used as \#, or as #! when starting a script
\                 Used at the end of a line to indicate continuation on to the next line
;                 Used to interpret what follows as a new command to be executed next
$                 Indicates what follows is an environment variable
>                 Redirect output
>>                 Append output
<                 Redirect input
|                 Used to pipe the result into the next command


Parameters




Command substitution



Variables

To export the variable in order to be valid also for the child processes:
export VAR=value
or
VAR=value ; export VAR
where "VAR" is the variable we want to export.

When a child process modifies a variable, that remains within the child processes and it doesn't affect the variable of the parent process. In other words, exporting means copying and inheriting.


Functions

Entering a function in a script means:
  1. Declaring a function
  2. Calling a function
The function declaration requires a name which is used to invoke it. The proper syntax is:
function_name () {
   command...
}







Comments