Automating Raspberry Pi Terminal Windows on Startup
This guide explains how to automatically open and configure multiple terminal windows with specific sizes, positions, and commands when you log into Raspberry Pi OS. This is the companion guide to macOS Terminal Startup.
Overview
Using shell scripts with LXTerminal options and the wmctrl window management tool, you can:
- Open multiple terminal windows automatically
- Position and size windows precisely on your screen
- Run startup commands in each window
- Execute this setup on login
Prerequisites
- Raspberry Pi running Raspberry Pi OS (Bookworm, Bullseye, or Buster)
- LXTerminal (installed by default on Raspberry Pi OS Desktop)
- Optional:
wmctrlfor precise window positioning
Install wmctrl if you need pixel-precise window control:
1 2 | |
Understanding Screen Coordinates
Terminal window positioning uses screen coordinates:
1 2 3 4 5 | |
- Origin (0,0) is the top-left corner of the screen
- X increases moving right
- Y increases moving down
- Panel is typically at the top (about 30 pixels tall)
Method 1: LXTerminal Geometry Options
LXTerminal supports geometry flags directly, making simple layouts easy without additional tools.
Geometry Format
The --geometry option uses the format: COLSxROWS+X+Y
COLS= width in characters (not pixels)ROWS= height in characters (not pixels)+X= horizontal position in pixels from left edge+Y= vertical position in pixels from top edge
Basic Script
Create a script at ~/bin/setup-terminals.sh:
1 2 3 4 5 6 7 8 9 10 11 12 13 | |
Make it executable:
1 2 | |
Running Commands on Startup
Use the -e flag to execute a command when the terminal opens:
1 2 3 4 5 6 7 8 | |
Method 2: Using wmctrl for Precise Positioning
For pixel-precise window control (similar to the macOS set bounds command), use wmctrl.
wmctrl Window Positioning Format
1 | |
-r "title"= select window by title-e= set window geometry0= gravity (0 = use default)X,Y= position in pixelsWIDTH,HEIGHT= size in pixels
Complete Example with wmctrl
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
Running Scripts at Login
Method 1: Autostart Desktop Entry (Recommended)
Create a .desktop file in the autostart directory:
1 2 | |
Add this content:
1 2 3 4 5 6 7 8 9 | |
The X-GNOME-Autostart-Delay=2 adds a 2-second delay to ensure the desktop is ready.
Method 2: LXDE Autostart File
For older Raspberry Pi OS versions using LXDE:
1 | |
Add your script with the @ prefix:
1 2 3 4 | |
Method 3: systemd User Service
For more control, create a systemd user service:
1 2 | |
Add:
1 2 3 4 5 6 7 8 9 10 11 12 | |
Enable the service:
1 | |
LXTerminal Options Reference
| Option | Description |
|---|---|
--geometry=COLSxROWS+X+Y |
Set size (chars) and position (pixels) |
--title="Name" |
Set window title |
-e "command" |
Execute command in terminal |
--working-directory=/path |
Set starting directory |
-T "Name" |
Alternative way to set title |
wmctrl Commands Reference
| Command | Description |
|---|---|
wmctrl -l |
List all windows |
wmctrl -r "title" -e 0,X,Y,W,H |
Move and resize window |
wmctrl -r "title" -b add,maximized_vert |
Maximize vertically |
wmctrl -r "title" -b add,maximized_horz |
Maximize horizontally |
wmctrl -a "title" |
Activate (focus) window |
Finding Your Screen Resolution
Check your display resolution:
1 2 3 4 5 6 7 8 | |
Comparison with macOS
| Feature | macOS | Raspberry Pi |
|---|---|---|
| Scripting method | AppleScript via osascript |
Bash + wmctrl |
| Terminal app | Terminal.app | LXTerminal |
| Profiles/themes | Built-in settings sets | Config file ~/.config/lxterminal/lxterminal.conf |
| Window positioning | set bounds {l,t,r,b} |
--geometry or wmctrl -e |
| Position format | Left, Top, Right, Bottom | X, Y, Width, Height |
| Autostart | Login Items or LaunchAgent | .desktop file or LXDE autostart |
Troubleshooting
Windows Don't Position Correctly
Cause: Screen dimensions in script don't match your display.
Solution: Check your actual resolution with xrandr and update the SCREEN_WIDTH and SCREEN_HEIGHT variables.
wmctrl Can't Find Window
Cause: Window title doesn't match exactly, or window hasn't opened yet.
Solution:
1. Use wmctrl -l to see exact window titles
2. Add longer sleep delays between opening and positioning
Script Works Manually But Not at Login
Cause: The script runs before the desktop is ready.
Solution: Add a delay at the beginning of your script:
1 | |
Or use X-GNOME-Autostart-Delay in the .desktop file.
Permission Denied
Cause: Script isn't executable.
Solution:
1 | |
Terminal Opens But Command Doesn't Run
Cause: Command exits immediately and terminal closes.
Solution: Keep the shell open after the command:
1 | |
Tips and Best Practices
-
Use delays between windows - A
sleep 0.5between window creation prevents race conditions. -
Test coordinates manually - Use
wmctrl -lto see window positions and adjust. -
Keep scripts in ~/bin - Add
export PATH="$HOME/bin:$PATH"to your~/.bashrcfor easy access. -
Document your layout - Add ASCII art comments showing your intended window arrangement.
-
Handle multiple monitors - If using multiple displays, coordinates extend beyond the primary screen width.
Complete Working Example
Here's a full script you can customize:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | |
See Also
- macOS Terminal Startup - Companion guide for macOS
- LXTerminal Documentation
- wmctrl Manual
- Raspberry Pi Documentation