Client Event Script For Switching User

So I created a timer-based script for switching users after a preset time. I used the following structure: system.security.switchUser(username, password, event, hideError ). What would go into the event parameter?
All I'm trying to accomplish is logging out of any other user that maybe logged in, and re-logging back in to a lower-level user.

if system.util.getInactivitySeconds () >15:
system.security.switchUser(Default,Default,WHATGOESHERE??,0)

You don't have to pass anything for the event parameter. It's optional.

Okay. Any other things I should be looking at?...the script doesn't seem to be executing.

Post your actual, complete code. Not a screenshot. Paste it into a comment. Select all of the code and then click the "Preformatted Text" button to make a code block.

if system.util.getInactivitySeconds () >15:
	system.security.switchUser(Default,Default,(),0)

I see a space between the () and getInactivitySeconds, but that may be a typo. You will also want to check the current user before you switchUser otherwise you will switch user every 15 seconds no matter who is logged in. I've made that mistake myself. Is Default the string name, or a variable?

if system.util.getInactivitySeconds() > 15 and system.security.getUsername() != "Default":
    system.security.switchUser("Default","Default")

The manual doesn't list the event parameter as optional.
system.security.switchUser - Ignition User Manual 8.1 - Ignition Documentation (inductiveautomation.com)

Edit:
Well, it does say if specified, ... but I think the optional tag would be helpful.

Worked like a charm. Thanks so much!!

1 Like

I'm not sure what language you might be coming from, but it's worth pointing out:
Python optional parameters are truly optional. You don't have to specify a default or empty value; you just don't specify one at all.

What you're doing here is passing an empty tuple for the event parameter. It's up to the function you're calling if passing the "wrong" type throws an error, is ignored, or does something different from your expectation.