Skip to content
Jean-Philippe Reculeau edited this page Oct 2, 2026 · 18 revisions

The Executor module displays an icon, and a label, on the basis of a script output, refreshed in user-defined intervals or on a signal. You may assign mouse events to it.

image

Script output

Output of the "script" command should return 1 or 2 lines, or 3+ lines to also set a tooltip (see below).

2 lines long output

By default we expect the icon path in the first line, and some text in the second one, e.g:

$ psuinfo -IM
/usr/share/psuinfo/mem.svg
3.1/21.5 GB

The Executor module will also accept an icon name:

$ /home/piotr/.config/nwg-panel/executors/arch_updates.py
software-update-urgent
1/2

1 line long output

We expect either a line of text:

$ psuinfo -CM
3.2/21.5 GB

or an icon path, or icon name.

The "continuous output" feature known from tint2 is not supported.

3 or more lines: dynamic tooltip

Available in the master branch, will ship with the release following v0.12.0 (#439).

If the script prints 3 lines or more, everything after the 2nd line becomes the executor tooltip, refreshed together with the icon and the label:

Line Content
1 icon path or icon name — may be empty (no icon)
2 label — may be empty (no label)
3+ tooltip, in Pango markup, may span several lines

This lets a single script show a compact value in the panel, and the details on mouse hover — no second executor, no popup window.

#!/bin/sh
# Load average in the panel, details in the tooltip
read l1 l5 l15 rest < /proc/loadavg
echo "utilities-system-monitor"
echo "$l1"
echo "<b>Load average</b>"
echo "1 min: <tt>$l1</tt>   5 min: <tt>$l5</tt>   15 min: <tt>$l15</tt>"
echo "$(uptime -p)"
$ ~/.config/nwg-panel/executors/load.sh
utilities-system-monitor
0.42
<b>Load average</b>
1 min: <tt>0.42</tt>   5 min: <tt>0.37</tt>   15 min: <tt>0.30</tt>
up 3 days, 2 hours, 11 minutes

Notes:

  • Scripts printing 1 or 2 lines behave exactly as before.
  • The dynamic tooltip takes precedence over the static "tooltip-text" setting. If the script goes back to 1 or 2 lines, the static "tooltip-text" (or no tooltip) is restored.
  • Each line is stripped of leading and trailing whitespace, so indent with markup (e.g. <tt>) rather than with spaces.
  • The tooltip is Pango markup: escape &, < and > in your data (&amp;, &lt;, &gt;). Invalid markup breaks the tooltip (GTK prints a warning).
  • With the 1st line empty and the 2nd line empty, nothing is shown in the panel — keep at least one of them.

Image in the tooltip

If the 3rd line is the path to an existing .svg or .png file, this image is shown at the top of the tooltip, and lines 4+ are shown below it as Pango markup:

Line Content
1 icon path or icon name (may be empty)
2 label (may be empty)
3 tooltip image: path to an existing .svg / .png file
4+ tooltip markup (optional)

Typical use: graphs (e.g. per-core CPU usage history) generated by the script, instead of text or Unicode bars.

#!/bin/sh
# Memory usage: value in the panel, a gauge + details in the tooltip
img="${XDG_RUNTIME_DIR:-/tmp}/mem-tooltip.svg"
used=$(LC_ALL=C free -m | awk '/^Mem:/ {printf "%d", ($2 - $7) * 100 / $2}')
# write to a temporary file, then rename: the panel never reads a half-written image
cat > "$img.tmp" <<EOF
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="16">
  <rect width="200" height="16" rx="3" fill="#31363b"/>
  <rect width="$((used * 2))" height="16" rx="3" fill="#3daee9"/>
</svg>
EOF
mv -f "$img.tmp" "$img"
echo "memory"
echo "$used %"
echo "$img"
echo "<b>Memory</b> $used % used"

Notes:

  • The image is shown at its native size (it is not scaled to "icon-size"): size your SVG / PNG for the tooltip.
  • It is left-aligned, with the markup below it, also left-aligned.
  • The script may rewrite the same file on every run: the image is reloaded when its modification time changes, and only then (no reload while the file is unchanged). It is read when the tooltip is displayed.
  • If the 3rd line is not a path to an existing .svg / .png file, it is treated as the first line of the markup (the plain tooltip above).
  • If the script stops printing the image line, the plain markup tooltip is used again.
  • When generating SVG with awk / printf, force a C locale (LC_ALL=C): in many locales decimal numbers get a comma (12,5), which breaks SVG coordinates. Setting LC_NUMERIC is not enough if LC_ALL is set in the panel environment.

Generated images in the panel

Same release (#441).

The panel icon (1st line) is reloaded when its path changes or when the file is rewritten at the same path (modification time). A script can therefore regenerate one image file on each run — e.g. a fixed-width SVG with small live graphs — and print the same path every time. With older versions, the image was only reloaded when the path changed (a common workaround was to alternate between two file names).

Images given as a path are scaled to fit a square of "icon-size" pixels, aspect ratio kept: for a wide image (e.g. 688 × 28 px), set "icon-size" to its width.

Database

Executors database is a common file to store your executors in. You may add your executor to it, and then import it to any other panel. Available since v0.5.7.

image

Also check Some useful executors.

Refreshing executors on RT signals

Starting from v0.7.15 you can give up on the refresh interval (set the value to 0), and force refreshing executors on a signal in range SIGRTMIN - SIGRTMAX:

image

The example executor below shows the current keyboard layout, and switches layouts on left click. Read comments for details.

#!/usr/bin/env python3

"""
Sway keyboard layout label & switcher, as an executor for nwg-panel
Author: Piotr Miller
e-mail: nwg.piotr@gmail.com
GitHub: https://github.com/nwg-piotr/nwg-panel
Project: https://github.com/nwg-piotr/nwg-shell
License: MIT

Usage:
0. Save this script as 'keyboard-layout' on your $PATH (e.g. '~/bin/keyboard-layout` or '~/.local/bin/keyboard-layout`).
1. Edit, to enter your `keyboard_id`, preferred `icon` and `sig_num`.
2. In nwg-shell-config create a new executor called "executor-keyboard".
3. Set "Script" to "keyboard-layout".
4. Set "On left click" to "keyboard-layout -s".
5. Set "Interval" to 0.
6. Set "Refresh on signal" to 37 (or whatever else you choose as the `sig_num` below); check the "use signal" box.
7. Add the executor to the panel.

Setting multiple keyboard layouts:
Nwg-shell users: in the config utility set comma-separated keyboard layouts, like e.g. "pl,us".
Others: do the same in your sway config file.

Dependency: `python-i3ipc`
"""

import argparse
import subprocess
import sys

from i3ipc import Connection

# Find your keyboard identifier with `swaymsg -t get_inputs`, paste here.
keyboard_id = "9610:42:SINO_WEALTH_Gaming_KB__Keyboard"

# Place your preferred icon name (or path) here. Leave empty ("") for no icon.
icon = "input-keyboard"

# The number of the signal to refresh the executor label, in range SIGTRMIN - SIGRTMAX (probably 34 - 64).
# You may check available range with `kill -l`.
sig_num = 37

i3 = Connection()


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("-s",
                        "--switch",
                        action="store_true",
                        help="switches keyboard layout")
    args = parser.parse_args()

    if args.switch:
        i3.command('input "{}" xkb_switch_layout next'.format(keyboard_id))

        # Send refresh signal to nwg-panel
        subprocess.Popen('pkill -{} nwg-panel'.format(sig_num), shell=True,
                         stdout=subprocess.DEVNULL,
                         stderr=subprocess.STDOUT)
        sys.exit(0)

    # Get keyboard layout name
    layout_name = ""
    inputs = i3.get_inputs()
    for i in inputs:
        if i.identifier == keyboard_id:
            layout_name = i.xkb_active_layout_name
            break

    if icon:
        # Print 2 lines: 1. icon name/path; 2. keyboard layout name.
        print("{}\n{}".format(icon, layout_name))
    else:
        # Print the keyboard layout name.
        print("{}".format(layout_name))


if __name__ == '__main__':
    main()

Clone this wiki locally