Skip to content

5 Script messages

Deulfi edited this page Oct 7, 2026 · 1 revision

ucm registers script messages that can be triggered from input.conf, other scripts, or uosc button commands.

For input.conf / general use

Message Effect
set statename All buttons with the given state show it; writes the current-state index to user-data/ucm_currstate
cycle Next state per state_cycle_map (writes ucm_currstate)
cycle-back Previous state (writes ucm_currstate)
set-default statename Marks a different state as the default; it swaps its cycle position with the old default, and the modifier key that pointed at the old default now shows the new state (inputevent is not re-registered)
revert-default Restores the original default state (the one from startup)
ctrl+1    script-message-to    ucm    set    state_1
ctrl+3    script-message-to    ucm    cycle
ctrl+4    script-message-to    ucm    cycle-back

For other scripts

The first argument is the calling script's name (so the replies come back to you); replies arrive as receive-<message> with the payload as arguments.

Message Effect
get-buttons recipient All buttons as a JSON map (receive-buttons)
set-buttons buttons_json Sets all buttons (JSON map button_name → {state_name → fields})
get-button recipient button_name One button as JSON (receive-button)
set-button button_name button_json Sets one button (receive-button reply with the button name)
get-state-map recipient The current state_map as JSON (receive-state-map)
set-state-map new_map Sets the state_map (state:KEY,…), re-parses the new states and re-registers the inputevent bindings (when inputevent is in use)
get-cycle-states recipient The state_cycle_map as JSON
set-cycle-states new_states Sets the state_cycle_map
swap-default value button_name Promotes the state whose active field carries the [[<prop>?!value]] marker (see Placeholders) to the button's default state
cycle-prop-values property values… Advances a user-data/<property> to the next value in the list (ucm appends this to the command of value-cycle buttons)
update-button button_name Re-translates one button (should be automatic; manual fallback)

Readiness (ucm_ready / ucm-refresh-done)

ucm registers its handlers while scripts are loading. Messages sent before it is ready are dropped, so a script that drives ucm should wait:

  • ucm_ready — ucm has loaded and registered its handlers. Safe to send set-state-map after this.
  • ucm-refresh-done — ucm has finished pushing the current buttons to uosc. Safe to rely on button round-trips after this.
mp.register_script_message('ucm_ready', function()
    mp.commandv('script-message-to', 'ucm', 'set-state-map',
        'state_1:default,state_2:MBTN_RIGHT,state_3:MBTN_MID')
end)

mp.register_script_message('ucm-refresh-done', function()
    mp.commandv('script-message-to', 'ucm', 'get-button', script_name, 'example')
end)

See Examples for the full injection pattern.

Details and caveats

  • Compact JSON — script-message arguments are split on whitespace, so JSON payloads must be compact (no spaces). mp.utils.format_json output qualifies; pretty-printed JSON does not.
  • set-button deep-copies its payload before fill-up, so the sending script's tables are not mutated; unknown state names are logged, not silently dropped.
  • set-state-map makes new state names reachable by set / cycle immediately (it re-parses states); unlike set-default, it does re-bind the inputevent keys (when inputevent is in use).
  • set maps the state to a ucm_currstate index (its position in the cycle map) — ?(c) displays it.

Clone this wiki locally