Set user default group from command line


is there a way to set a user’s default group from the CLI tool?

When users are created in our system they are automatically a member of a group called ‘default’ for storing private images.

I can add a batch of users to a new group with the cli tool, but how can set this new group to be their default group.



There isn’t, it remains an RFE at [trello] CLI manage group and user Missing features I’m afraid. It’s quite feasible though, a client-side Python script could use

1 Like

Hi Chris,
Here’s a tiny script that works for me (minimal testing) to get you started:

import argparse
import sys

import omero.clients
from omero.cli import cli_login
from omero.gateway import BlitzGateway
from omero.model import ExperimenterGroupI

def main(argv):
    parser = argparse.ArgumentParser()
    parser.add_argument('username', help='Username')
    parser.add_argument('group_id', type=int, help=(
        'Set this group to be the default'))
    args = parser.parse_args(argv)

    with cli_login() as cli:
        conn = BlitzGateway(client_obj=cli._client)
        admin_service = conn.getAdminService()

        user = admin_service.lookupExperimenter(args.username)
        group = ExperimenterGroupI(args.group_id, False)
        admin_service.setDefaultGroup(user, group)

if __name__ == '__main__':

Save that as e.g.

Then you can do this (it will use your existing cli login, or ask you to login):

$ python username 3

Hope that helps. I’m sure you can improve it to your liking,


1 Like

Hi @will-moore and @mtbc,

thanks so much for the speedy replies. The code is really helpful as it always takes me a while to change gear from using the java API (in jython) to using the python API.