How to create Unity indicators?

I’m interested in Unity indicators and wonder if there is any tutorial on how to program them. I can use the sources of the existing ones as last resort, but I’d prefer a more friendly approach because my programming skills are quite limited.

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

Application Indicator documentation with examples and API docs are available here:

There are not yet tutorials on Application Indicators there yet, but stay tuned for more content on the App Developer site’s tutorials section:

Solution 2

Here is an app indicator example in C. This is an “indicator only” version (no window) of the example provided at Ubuntu Wiki:

#include <libappindicator/app-indicator.h>

static void activate_action (GtkAction *action);

static GtkActionEntry entries[] = {
    {"New",  "document-new",     "_New",  "<control>N",
        "Create a new file",    G_CALLBACK(activate_action)},
    {"Open", "document-open",    "_Open", "<control>O",
        "Open a file",          G_CALLBACK(activate_action)},
    {"Save", "document-save",    "_Save", "<control>S",
        "Save file",            G_CALLBACK(activate_action)},
    {"Quit", "application-exit", "_Quit", "<control>Q",
        "Exit the application", G_CALLBACK(gtk_main_quit)},
static guint n_entries = G_N_ELEMENTS(entries);

static const gchar *ui_info =
"  <popup name='IndicatorPopup'>"
"    <menuitem action='New' />"
"    <menuitem action='Open' />"
"    <menuitem action='Save' />"
"    <menuitem action='Quit' />"
"  </popup>"

static void activate_action(GtkAction *action)
    const gchar *name = gtk_action_get_name (action);
    GtkWidget *dialog;

    dialog = gtk_message_dialog_new(NULL,
                                    "You activated action: \"%s\"",

    g_signal_connect(dialog, "response", 
                     G_CALLBACK(gtk_widget_destroy), NULL);


int main(int argc, char **argv)
    GtkWidget*      indicator_menu;
    GtkActionGroup* action_group;
    GtkUIManager*   uim;
    AppIndicator* indicator;
    GError* error = NULL;

    gtk_init(&argc, &argv);

    /* Menus */
    action_group = gtk_action_group_new("AppActions");
    gtk_action_group_add_actions(action_group, entries, n_entries,

    uim = gtk_ui_manager_new();
    gtk_ui_manager_insert_action_group(uim, action_group, 0);

    if (!gtk_ui_manager_add_ui_from_string(uim, ui_info, -1, &error)) {
        g_message("Failed to build menus: %s\n", error->message);
        error = NULL;

    /* Indicator */
    indicator = app_indicator_new("example-simple-client",

    indicator_menu = gtk_ui_manager_get_widget(uim, "/ui/IndicatorPopup");

    app_indicator_set_status(indicator, APP_INDICATOR_STATUS_ACTIVE);
    app_indicator_set_attention_icon(indicator, "indicator-messages-new");

    app_indicator_set_menu(indicator, GTK_MENU(indicator_menu));


    return 0;

Solution 3

I did a short tutorial here for creating a stop watch app indicator in python:

import gobject
import gtk
import appindicator
import os, sys
import time
from datetime import timedelta

if __name__ == "__main__":

    saveseconds = 0 #global variable to save how many seconds the clock has run
    dir_path = os.path.dirname(os.path.realpath(__file__))
    source_id = ""

    def on_timer(args=None):
      savetime = int(time.time() - timestart) + saveseconds
      return True

    def finish(args=None):
        return True

    def stoptime(args=None):
        global saveseconds
        saveseconds += int(time.time() - timestart)
        return True

    def starttime(args=None):
        global timestart
        timestart = time.time()
        global source_id
        source_id = gtk.timeout_add(1000, on_timer)
            #sets timer to run every 1s
        return True

    def cleartime(args=None):
        global saveseconds
        saveseconds = 0
        return True

    #format below is category name, icon
    ind = appindicator.Indicator ("simple-clock-client", "hourglass", appindicator.CATEGORY_APPLICATION_STATUS, dir_path)
    ind.set_status (appindicator.STATUS_ACTIVE)
    ind.set_label("Elapses"); #name of program and initial display

    ##Setup Menu Items
    menu = gtk.Menu()

    stop = gtk.MenuItem("Stop")
    stop.connect("activate", stoptime)

    start = gtk.MenuItem("Start")
    start.connect("activate", starttime)

    clear = gtk.MenuItem("Clear")
    clear.connect("activate", cleartime)

    exit = gtk.MenuItem("Exit")
    exit.connect("activate", finish)

    ind.set_menu(menu) #set the menu with added items

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply