raul1st2002 Posted September 21, 2016 Report Share Posted September 21, 2016 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.discover', self.discover) self.session.event_hub.subscribe('topic=ftrack.action.launch and data.actionIdentifier={0}'.format(self.identifier), self.launch) 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: return selection = event['data']['selection'] if len(selection) != 1: return 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): webbrowser.open(path) os.system('xdg-open "%s"' % path) return {'success': True, 'message': 'Success'} else: return {'success': False, 'message': 'No such directory.'} Link to comment Share on other sites More sharing options...
natasha Posted September 21, 2016 Report Share Posted September 21, 2016 When you register the launch event add the source.user.username so that the action only launches for that user. self.session.event_hub.subscribe( 'topic=ftrack.action.launch and source.user.username={0} ' 'and data.actionIdentifier={1}'.format( getpass.getuser(), self.identifier ), self.launch ) Link to comment Share on other sites More sharing options...
raul1st2002 Posted September 22, 2016 Author Report Share Posted September 22, 2016 Thank you Natasha. That works! Link to comment Share on other sites More sharing options...
jerome Posted January 11, 2017 Report Share Posted January 11, 2017 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 ? cheers, Link to comment Share on other sites More sharing options...
Martin Pengelly-Phillips Posted January 11, 2017 Report Share Posted January 11, 2017 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: self.session.event_hub.subscribe( 'topic=ftrack.action.launch and ' 'data.actionIdentifier={0} and ' 'data.variant="{1}"' .format(self.identifier, self.variant), self.launch) ) Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.