The Cookie Machine - Click here to drag window

DUMMY TEXT - Real text set in assets/js/theCookieMachine.js

Views: 2,092     Votes:  6     ✅ Solution
Tags: unity   bash   scripts   system-tray   eyesome   multi-timer  
Link: 🔍 See Original Answer on Ask Ubuntu 🔗

Title: Can BASH display in systray as application indicator?
ID: /2017/02/11/Can-BASH-display-in-systray-as-application-indicator_
Created: February 11, 2017    Edited:  December 12, 2021
Upload: August 14, 2022    Layout:  post
TOC: false    Navigation:  true    Copy to clipboard:  false


System Monitor Indicator

The best method I’ve found is Sysmonitor Indicator from this article on the WEB UPD8 website:

It displays text on the Ubuntu System Tray (Systray) / Application Indicator Bar that your bash script updates with a single echo command.

Top ToS Skip

Different Desktop Environments

The above article is targeted to Ubuntu 14.04 to 20.04 with the Unity Desktop. If you don’t have Unity Desktop installed for Ubuntu 20.04 see these instructions.

For more information on Xubuntu, Gnome-Shell + app-indicator extension, and Budgie, go to the Developers website: fossfreedom / indicator-sysmonitor. Also visit the site for more detailed installation and configuration instructions.

Install and Configure indicator-sysmonitor

To install System Monitor Indicator you need to first specify the PPA where indicator-sysmonitor can be found:

sudo add-apt-repository ppa:fossfreedom/indicator-sysmonitor
sudo apt-get update
sudo apt-get install indicator-sysmonitor

Now run the “indicator-sysmonitor” GUI from Unity Dash (Alt+F2 or ⊞ Super aka ⊞ Win key). If you are using GNOME use ⊞ Super+A to open Show Applications instead of Dash.

Top ToS Skip

Sysmonitor Indicator in action

This .gif shows how it looks when Ubuntu’s Unity System Tray is updated.

multi-timer sysmonitor indicator.gif

Top ToS Skip

Sysmonitor Indicator BASH script

Create a script similar to the following script called indicator-sysmonitor-display. Assign the script’s filename to the variable {Custom} in Sysmonitor Indicator:


# UPDT: May 30 2018 - Cohesion with new multi-timer and old lock-screen-timer.
#       July 6 2020 - New eyesome sunlight percentage.

if [ -f ~/.lock-screen-timer-remaining ]; then
    Spinner=$(cat ~/.last-text-spinner) # read last text spinner used
    String=$(cat ~/.lock-screen-timer-remaining)
    systray="$Spinner  $String"

if [ -f /usr/local/bin/.eyesome-percent ]; then
    Brightness=$(cat /usr/local/bin/.eyesome-percent)
    systray="$systray  eyesome: $Brightness"
    systray="$systray  eyesome: OFF"

# Below for AU answer:
# default_interface=$(route -n | awk '$1 == "" {print $8; exit}')
# ip_address=$(ifconfig "$default_interface" | awk 'sub(/.* inet addr:/, "") {print $1}')
# systray="$systray  $ip_address"
echo "$systray" # sysmon-indidicator will put echo string into systray for us.

exit 0

After telling Sysmonitor Indicator the name of your bash script by setting the {Custom} variable it runs every refresh interval. Whatever your bash script outputs via echo command appears in Ubuntu’s System Tray.

Top ToS Skip

Three bash scripts that output to Systray

The indicator-sysmonitor-display script displays Time Remaining and Display Brightness Level values. These values are set by other scripts documented within Ask Ubuntu:

These three bash scripts illustrate how multiple scripts can output to the Systray concurrently and share the same script file (indicator-sysmonitor-display) that updates the display.

Spinning pizza–text-spinner BASH script

The text-spinner bash script creates a spinning pizza effect by cycling through the characters |, /, and \. This effect highlights the fact something is “working” or “thinking”. To get the “spinning effect” you want to change the Sysmonitor Indicator refresh interval from the default 2 seconds to be about 0.30 seconds.

Here is the text-spinner bash script:


# return '|', '/', '─', '\' sequentially with each call to this script.
# Use ~/.last-text-spinner to store last used


if ! [ -f $FILE ]; then
    echo '|' > $FILE
    exit 124 # ASCII equivalent for '|'. Bash doesn't allow character return codes

LAST=$(cat $FILE) # read last character used

if [[ $LAST == '|' ]]; then
    echo '/' > $FILE
    exit 47 # ASCII equivalent of "/"
elif [[ $LAST == '/' ]]; then  # NOTE: you must have spaces around " == " else code breaks
    echo '─' > $FILE
    exit 9472 # ASCII equivalent
elif [[ $LAST == '─' ]]; then
    echo '\' > $FILE # NOTE: must use single quote because double quote BASH reinterprets
    exit 92 # ASCII
    echo '|' > $FILE
    exit 124 # ASCII

Top ToS
⇧ Considerations for using `/tmp` directory on multi-user systems How to display something in unity systray from a bash script  ⇩