commands get executed on mutiple subscribers via actions

5 posts in this topic

Hi guys,

I'm writing an action that opens the file path for a selected entity. 

When I launch the action, it acutually opens the file exploerer on every computer which is running ftrack connect.

How can I restrict the command only excutes on the local caller?

Thank you for your help!



My code -----------------------------------------------------------------------------------------------------------------------------------

def register(self):

    self.session.event_hub.subscribe('topic=ftrack.action.launch and data.actionIdentifier={0}'.format(self.identifier),

def discover(self, event):
    # Check ftrack user == system user
    connect_user = event['source']['user']['username'].split('@')[0]
    sys_user = getuser().split('@')[0]

    if connect_user != sys_user:

    selection = event['data']['selection']
    if len(selection) != 1:

    return {'items': [{'label': self.label,
                       'description': self.description,
                       'actionIdentifier': self.identifier}]}

def launch(self, event):
    path = utils.get_entity_root(self.entity)
    if os.path.exists(path):
        os.system('xdg-open "%s"' % path)
        return {'success': True,
                'message': 'Success'}
        return {'success': False,
                'message': 'No such directory.'}

Share this post

Link to post
Share on other sites

When you register the launch event add the source.user.username so that the action only launches for that user.

      'topic=ftrack.action.launch and source.user.username={0} '
      'and data.actionIdentifier={1}'.format(
      getpass.getuser(), self.identifier


Share this post

Link to post
Share on other sites

Hi there,

This would however not be complete if the same user launch program from a different machine...

I can't find anything in the event['source'] which would allow me to filter event to be run on a specific machine.

Is there a way to do this ?




Share this post

Link to post
Share on other sites

And of course you might even have multiple copies of the same listener running on a single machine ;-)

Generally you need to include extra information in the returned action description and filter against it in your subscribe expression.

One option is to make use of the 'variant' key as it presents nicely to the user. Something like (untested):

self.variant = '{} ({})'.format(socket.getfqdn(), os.getpid())

return {
    'items': [
            'label': self.label,
            'variant': self.variant,
            'description': self.description,
            'actionIdentifier': self.identifier

And filter on variant in your subscribe expression:

    'topic=ftrack.action.launch and '
    'data.actionIdentifier={0} and '
    .format(self.identifier, self.variant), 


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now