Bernhard's Homepage

GNS3 - Extend the OS X GUI Application

GNS3 - Extend the OS X GUI Application

In Mac OS X an application can be extended by adding services. This feature can be used to add new functionality to GNS3.
GNS3 Services

The easiest way is doing that with the help of Automator. In the following a command line application will be integrated.

First open the Automator application and add a new service. Set "Service receives" to "no input" and the application to GNS3. Enter "shell" into the search box and drag "Run Shell Script" from the left into the workflow area. Then set the shell to /bin/sh and "Pass input" to "as arguments".

Automator workflow

The following shell script is starting the application, in this case GNS3/scripts/close_project. If an error occurs, an alert box will show the error message.

cd; PATH=/usr/local/bin:$PATH

err_str=`GNS3/scripts/close_project 2>&1`
[ $? -eq 0 ] && exit 0

osascript \
    -e 'on run argv' \
    -e '    set text item delimiters to " "' \
    -e '    set errStr to argv as text' \
    -e '    display alert "Close project" & return & return & errStr as critical giving up after 10' \
    -e 'end run' \
    -- "$err_str" > /dev/null

Insert/replace the script, save it and give it a descriptive name. This name will show up in the service menu. The file is stored in the Library/Services directory.

You can even add a shortcut to this service. Open <any application> / Services / Services Preferences, scroll down to the bottom of the list, where you should find the newly created service. Then click on the shortcut definition on the right of it (initially its "none") and assign a shortcut.

Well, that integrates a command line application. But now we actually need that application. Normally it's the other way round. You have written an application, tested it and then want to integrate it.

My demo application closes an open project. It uses the GNS3 API to get a list of projects. If only one is open, it closes it. If started from the CLI, you can specify the project name as a parameter.

Here's the application, save it and make it executable (chmod +x). It needs Python 3, that can be installed from

# close_project - close GNS3 project
# Usage: close_project [project]

import sys
import gns3api

def die(*msg_list):
    """ abort program with error message """
    error_msg = ' '.join(str(x) for x in msg_list)

# get command line parameter
if len(sys.argv) <= 1:
    proj_name = None
elif len(sys.argv) == 2:
    proj_name = sys.argv[1]
    die("Usage: close_project [project]")

# connect to GNS3 controller
    api = gns3api.GNS3Api()
except gns3api.GNS3ApiException as err:
    die("Can't connect to GNS3 controller:", err)

# search for the project
project = None
if proj_name is None:		# search for the only open project
    for proj in api.request('GET', '/v2/projects'):
        if proj['status'] == 'opened':
            if project is None:
                project = proj
                die("Multiple projects active, set project as first param")
    if project is None:
        die("No project is open")
else:				# search for proj_name
    for proj in api.request('GET', '/v2/projects'):
        if proj['name'] == proj_name:
            if proj['status'] != 'opened':
                die("Project '{}' not open".format(proj_name))
            project = proj
        die("Project '{}' not found".format(proj_name))

print("Closing {}...".format(project['name']))
api.request("POST", ("/v2/projects", project['project_id'], "close"))

But that results in another issue (I should have warned you, that this is advanced stuff):

I'm using a Python library to ease the access to the GNS3 API. I've created a very simple python module named gns3api, see You have to download and store it in the same directory as the python script.

David Flores has created another python module, that interfaces to the GNS3 API: gns3fy ( I haven't tried that, but it looks very promising. My demo program would need mayor changes to use this module.