LM-Studio-Tray-Manager Documentation

Estimated read time: calculating…

Introduction

This documentation covers the LM Studio automation setup and scripts. The project provides:

The lmstudio_autostart.sh script ensures the LM Studio daemon is running, waits for the API, optionally loads a model, and starts the tray monitor. When dist/lmstudio-tray-manager exists, the autostart script prefers the binary and forwards flags. The lmstudio_tray.py script provides a system tray icon for real-time monitoring and quick actions.

All log files are written to the .logs/ directory for easy access and cleanup.

Setup Guide

The setup process automatically detects your installation type and handles all prerequisite checks, including GTK3/GObject libraries required for the system tray.

Quick Start

./setup.sh

The setup script will:

After setup, run:

# Binary release
./lmstudio-tray-manager --auto-start-daemon

# Python package release
./lmstudio_autostart.sh

For complete setup instructions, advanced options, troubleshooting, and detailed configuration: See SETUP.md

For building your own binary: See BUILD.md

Configuration

Tray Monitor API Configuration

The tray monitor stores its configuration in ~/.config/lmstudio_tray.json:

{
  "api_host": "localhost",
  "api_port": 1234
}

Edit via Left-click → Options → Configuration in the tray menu.

Environment Variables

For detailed configuration options, environment setup, and troubleshooting: See SETUP.md

Usage

Common Commands

# Start daemon with tray monitor
./lmstudio_autostart.sh

# Start GUI (stops daemon first)
./lmstudio_autostart.sh --gui

# Interactive model selection
./lmstudio_autostart.sh --list-models

# Debug mode
./lmstudio_autostart.sh --debug

# Binary release
./lmstudio-tray-manager --auto-start-daemon

Monitor Logs

tail -f .logs/lmstudio_tray.log

For complete usage guide, all CLI options, system tray interface, model management, and application troubleshooting: See USE.md

Logging & Troubleshooting

All logs are written to the .logs/ directory:

GLib schema error: if the binary aborts with a "Settings schema... does not contain a key named 'antialiasing'" message, install gsettings-desktop-schemas or launch with GSETTINGS_SCHEMA_DIR=/usr/share/glib-2.0/schemas. The tray attempts to set this variable automatically on startup.

Note: setup.log replaces `$HOME` with `~` to avoid exposing your home directory.

View Logs

tail -f .logs/lmstudio_tray.log
grep -i "error" .logs/*.log

Enable Debug Mode

./lmstudio_autostart.sh --debug

For detailed troubleshooting, setup issues, runtime problems, and comprehensive error guidance: See SETUP.md and USE.md

LM Studio Autostart Script (lmstudio_autostart.sh)

This Bash script automates the startup process of LM Studio. It performs the following main tasks:

Command Line Options

Usage: ./lmstudio_autostart.sh [OPTIONS]

            Options:
                -d, --debug       Enable debug output and Bash trace
                -h, --help        Show help and exit
                -L, --list-models List local models (interactive selection in TTY, then load selected model)
                -g, --gui          Start the LM Studio GUI (stops daemon first)

            Environment variables:
                LM_AUTOSTART_DEBUG=1            Force debug mode
                LM_AUTOSTART_SELECT_TIMEOUT=30  Timeout for interactive selection
                LM_AUTOSTART_GUI_CMD="..."      Explicit GUI start command

When dist/lmstudio-tray-manager exists, the script launches the binary instead of the Python script and forwards the same flags. With --gui, it forwards --gui; otherwise it forwards --auto-start-daemon. When debug is enabled, it forwards --debug to the tray monitor.

System Autostart Integration

To automatically start LM Studio daemon and tray monitor on login, create a desktop entry in ~/.config/autostart/:

mkdir -p ~/.config/autostart/
cat > ~/.config/autostart/lmstudio-daemon.desktop << 'EOF'
[Desktop Entry]
Type=Application
Name=LM Studio Daemon
Exec=/path/to/LM-Studio/lmstudio_autostart.sh
X-GNOME-Autostart-enabled=true
Hidden=false
EOF

Recommended Setup: Run ./lmstudio_autostart.sh without --gui flag in autostart. The daemon and tray monitor will start automatically. Users can then launch the desktop GUI on-demand via the tray monitor's "Start Desktop App" menu option.

Tray Monitor Script (lmstudio_tray.py)

This Python script creates a system tray icon for LM Studio runtime monitoring and mode switching. It provides:

Status Indicators (in Menu)

When you left-click the tray icon, the menu shows live status for each option:

Tray Icon Schema

Tray Menu Options

Model Detection & API Fallback

The tray monitor uses a two-tier approach for model detection to handle all runtime configurations:

  1. Primary (lms ps): When daemon is running, queries lms ps CLI command to get model status. This is the most reliable method.
  2. Fallback (API): When lms command fails (e.g., desktop app running independently) or returns no output, queries the LM Studio API directly at the configured endpoint. This enables model detection when only the desktop app is running.

This approach ensures accurate model status display across all daemon modes:

API Configuration & Security

The API endpoint is configurable via Options > Configuration. Configuration is stored securely at ~/.config/lmstudio_tray.json with the following settings:

Security Note: All API connections use HTTP/HTTPS schemes only. Other schemes (file://, ftp://, etc.) are rejected by the tray monitor to prevent URL scheme injection attacks. The configuration also validates that host and port values are properly formatted.

Binary Release (lmstudio-tray-manager)

The binary release contains a standalone tray monitor built with PyInstaller. It lets you run the tray without a local Python setup. The binary is included in the release archive and works with the same flags as the Python script.

Install and Run

# example (replace X.Y.Z with version)
VERSION=vX.Y.Z

# binary package
tar -xzf lmstudio-tray-manager-${VERSION}-linux-x86_64-binary.tar.gz
cd lmstudio-tray-manager-${VERSION}-linux-x86_64-binary

./setup.sh
./lmstudio-tray-manager --auto-start-daemon

Available Flags

Logs

The binary writes logs to .logs/lmstudio_tray.log in the release folder.

Flow Diagrams

Installation Paths Overview

Choose the installation method that best suits your needs:

graph TB User["👤 User
Has release files"] AppImg["📦 AppImage
(recommended)"] Bin["📦 Binary Release"] Src["📦 Source Package"] AppImg -->|"chmod +x"| Run1["Run directly
./lmstudio-tray-manager-*.AppImage"] AppImg -->|"Optional: verify
daemon & desktop app"| Setup["setup.sh"] Bin -->|"Make executable"| Run2["Run directly
./lmstudio-tray-manager --auto-start-daemon"] Bin -->|"or: verify deps"| Setup Src -->|"Required: setup
environment"| Setup Run1 -->|"Starts tray monitor"| Monitor["GTK3 System Tray
Monitors daemon & API"] Run2 -->|"Starts tray monitor"| Monitor Setup -->|"Shows appropriate
commands for your
installation type"| Run1 Setup -->|"or"| Run2 Setup -->|"or configure venv"| Src User --> AppImg User --> Bin User --> Src Monitor -->|"Connects to"| Daemon["LM Studio Daemon
(llmster)"] Daemon -->|"Manages"| Models["Model Files
(configurable)"]

System Architecture Overview

Key insight: AppImage is self-contained and runs directly. Binary releases also run directly. Only source packages require setup.sh to prepare the Python environment.

graph TB AppImg["AppImage Release
(Self-contained)"] Bin["Binary Release
(PyInstaller bundle)"] Src["Source Package
(Python source)"] AppImg -->|"Direct execution
chmod +x + run"| TrayBin["lmstudio-tray-manager
(AppImage runtime)"] Bin -->|"Direct execution
chmod +x + run"| TrayBin2["lmstudio-tray-manager
(PyInstaller binary)"] Src -->|"setup.sh
creates venv"| Autostart["lmstudio_autostart.sh
Daemon Orchestration"] Src -->|"or direct: activate venv
+ python3"| Tray["lmstudio_tray.py
GTK3 System Tray"] TrayBin -->|"Monitors"| Daemon["LM Studio Daemon
(llmster)"] TrayBin2 -->|"Monitors"| Daemon Autostart -->|"Orchestrates"| Daemon Tray -->|"Monitors"| Daemon Autostart -->|"Starts if needed"| TrayBin2 Autostart -->|"Fallback"| Tray Daemon -->|"Provides"| API["LM Studio API
host:port (configurable)"] Daemon -->|"Manages"| Models["Model Files"] TrayBin -->|"Monitors"| API TrayBin2 -->|"Monitors"| API Tray -->|"Monitors"| API

setup.sh - Optional Verification Script

Note: setup.sh is optional for AppImage and Binary releases. It automatically detects your installation type and helps verify dependencies.

graph TD A["setup.sh
START"] --> B["Check LM Studio Daemon"] B --> C["Check Desktop App"] C --> E{"Installation type?"} E -->|AppImage found| F["✓ AppImage Detected"] F --> Skip1["Skip GTK3 check
(bundled in AppImage)"] Skip1 --> H1["END (Success)
Ready to run:
./lmstudio-tray-manager-*.AppImage"] E -->|Binary found| G["✓ Binary Found"] G --> Skip2["Skip Python venv
Skip GTK3 check
(bundled in binary)"] Skip2 --> H2["END (Success)
Ready to run:
./lmstudio-tray-manager --auto-start-daemon"] E -->|Neither found| I["Python Source Release Detected"] I --> X["Check GTK3/GObject typelibs"] X --> D["Check Python + gi compatibility"] D --> J{"Compatible Python
with gi found?"} J -->|No| K["Install python3 + python3-gi
via apt"] J -->|Yes| L["Create venv
(./venv)"] K --> L L --> M["Enable system-site-packages
for GTK3/PyGObject"] M --> N["Upgrade pip & setuptools"] N --> O["Show Python Commands"] O --> O1["Ready to run:
./lmstudio_autostart.sh"] O1 --> P["END (Success)
Python environment ready"]

lmstudio_autostart.sh - Daemon Orchestration Script

The autostart flow always launches a tray monitor. A standalone binary is preferred when present.

graph TD A["lmstudio_autostart.sh
START"] --> B[Check system dependencies] B --> C{--gui flag?} C -->|Yes| D[Stop daemon] D --> E[Start LM Studio GUI] E --> S[Sanitize runtime environment
Remove Snap/GTK/Python vars] S --> L["Start tray monitor
(binary preferred; passes --gui)"] C -->|No| F[Start LM Studio daemon] F --> G[Wait for API
host:port
configurable] G --> H{Model specified?} H -->|Yes| J[Load model via lms CLI] H -->|No| K[Skip model loading] J --> S K --> S L --> I["END"]

lmstudio_tray.py - GTK3 System Tray Monitor

graph TD A["lmstudio_tray.py
START"] --> B[Kill existing instances] B --> C[Create GTK3 tray icon] C --> D[Set up left-click menu] D --> E[Start daemon/API monitoring] E --> F{Status check} F --> G{Model loaded?} G -->|Yes| H[Set OK icon ✅] G -->|No| I{Any runtime active?} I -->|Yes| J[Set INFO icon ℹ️] I -->|No| K{Installed?} K -->|Yes| W[Set WARN icon ⚠️] K -->|No| X[Set FAIL icon ❌] H --> L[Check for changes] J --> L W --> L X --> L L --> M{Status changed?} M -->|Yes| N[Send notification] M -->|No| O[Wait before
next check] N --> O O --> F F --> P{User action?} P -->|Start/Stop Daemon| Q[Switch to daemon mode] P -->|Start/Stop Desktop App| R[Switch to desktop app mode] P -->|Show Status| S[Show status dialog] P -->|Quit| T["END"] Q --> F R --> F S --> F

lmstudio-tray-manager - Standalone Binary

The standalone binary compiled from PyInstaller combines the tray monitor with command-line argument handling. No venv activation required.

graph TD A["lmstudio-tray-manager
START"] --> B["Parse command-line
arguments"] B --> C{Argument
provided?} C -->|--help| Help["Display help
and usage info"] Help --> EXIT1["END"] C -->|--version| Ver["Display version
info"] Ver --> EXIT2["END"] C -->|--debug| D["Enable debug mode
Verbose logging"] C -->|--auto-start-daemon| Auto["Auto-start daemon
and tray monitor"] C -->|--gui| Gui["Start LM Studio
GUI first"] C -->|No args| Default["Run as tray monitor
(default behavior)"] D --> RunStart["Kill existing
instances"] Auto --> RunStart Gui --> RunStart Default --> RunStart RunStart --> E["Create GTK3
tray icon"] E --> F["Set up left-click
menu"] F --> G["Start daemon/API
monitoring"] G --> H{Status
check} H --> I{Model
loaded?} I -->|Yes| J["Set OK icon ✅"] I -->|No| K{Any runtime
active?} K -->|Yes| L["Set INFO icon ℹ️"] K -->|No| M{Installed?} M -->|Yes| N["Set WARN icon ⚠️"] M -->|No| O["Set FAIL icon ❌"] J --> P["Check for
changes"] L --> P N --> P O --> P P --> Q{Status
changed?} Q -->|Yes| R["Send
notification"] Q -->|No| S["Wait before
next check"] R --> S S --> H H --> T{User
action?} T -->|Start/Stop
Daemon| U["Toggle
daemon"] T -->|Start/Stop
Desktop App| V["Toggle
desktop app"] T -->|Show Status| W["Display
status dialog"] T -->|Quit| X["END"] U --> H V --> H W --> H

Python Docstrings

The static docstrings documentation for lmstudio_tray.py is available as a dedicated page and uses the same visual design as this documentation.

Open Python Docstrings Reference

Official Resources

Learn more about LM Studio and stay updated with the latest developments: