{% extends "base.html" %} {% block title %}Scripts{% endblock %} {% block content %}

Scripts

{# Draft persistence: mid-typed REPL commands + in-progress batch scripts survive a navigation away and back. Restores from localStorage on DOMContentLoaded; clears on successful submit. #}

Interactive Python (REPL)

A live Python interpreter sharing the same namespace as the batch runner below — sensors, turnouts, InstanceManager, all preloaded. Type an expression to see its value; assign a variable and it survives across submissions. Click Reset to start over.

{% include "_repl_console.html" %}
Ctrl+Enter to submit · ↑/↓ recalls history

Run an inline script

Scripts run on a worker thread. The shim exposes JMRI-style globals: sensors, turnouts, lights, memories, powermanager, plus ACTIVE, CLOSED, ON etc. Define class X(AbstractAutomaton) to use the loop pattern. Tick "Save to profile library" to persist the script to <profile>/python/<name>.py so it autoloads the next time the server starts.

Debug loop: any script with a "saved" badge in the Running scripts table below gets a Run / Re-run button that re-reads the file fresh from disk each click — edit the file externally, click Run, watch output. Files dropped into <profile>/python/ while the server is up appear here after any list refresh.

Startup autoload opt-outs (three ways to keep a script on disk + runnable but skip startup):  ·  rename to _name.py (private, also hidden from Python imports)  ·  rename to lib_name.py (importable helper module, not autoexecuted)  ·  add # jmri-autoload: false anywhere in the first 20 lines (visible + runnable, just not at startup).

Running scripts

{% include "_scripts_table.html" %}
{% endblock %}