OSUsername from other Open Clients?

Anyway to get OSUsernames from the other open clients? I am currently using getSessionInfo() to see Project names and Addresses. Maybe I can do some sort of Message Handler where the other clients report back their OSUsernames? I have tested out system.util.sendMessage(). Need to test .sendRequest(), maybe that can be used for reporting OSUsernames of other open clients back to a Requesting client?

Sounds like you’re on the right track. You can use the getpass python module in the clients to return their OS usernames.

Keep in mind sendRequest only works from the client to the gateway, not the other way around. However, sendMessage can target a messageHandler in all open clients that tells them to append their OS username to a tag.

Here’s what worked for me:

  • In the inquiring client, first initialize a tag list, and then send your message:
	system.tag.write("client users", "")
	system.util.sendMessage(project="Office_Overview", messageHandler="get_os_user", scope="C")
	os_users_str = system.tag.read("client users").value
	os_user_list = os_users_str.split(",")
  • The “get_os_user” client message handler:
	import getpass
	user = getpass.getuser()
	userlist = system.tag.read("client users").value
	if userlist == '':
		system.tag.write("client users", user)
	else:
		system.tag.write("client users", userlist+','+user)
  • The final content of os_user_list:
[u'localadmin', u'bfuson']

Keep in mind the potential data hazard that could lead to one client quickly over-writing the first username. (I think)
Also the inquiring client must wait long enough for the others to respond before reading the tag.

1 Like