# Timer to Close Vision Popup Window

**URL:** <https://forum.inductiveautomation.com/t/timer-to-close-vision-popup-window/60460>\
**Category:** Ignition\
**Tags:** ignition81, vision, scripting\
**Created:** [June 7, 2022, 4:37pm UTC](https://forum.inductiveautomation.com/t/timer-to-close-vision-popup-window/60460 "2022-06-07T16:37:46Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![BRAD\_DAVIS](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/brad_davis/32/35392_2.png) [@BRAD\_DAVIS](https://forum.inductiveautomation.com/u/BRAD_DAVIS)\
**Post date:** [June 7, 2022, 4:37pm UTC](https://forum.inductiveautomation.com/t/timer-to-close-vision-popup-window/60460/1 "2022-06-07T16:37:46Z")

</div>

How do you create a timer to close a popup after it has been open for more then a set time.  
I want to close control screens after 15 seconds to stop people from leaving them open.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [June 7, 2022, 4:51pm UTC](https://forum.inductiveautomation.com/t/timer-to-close-vision-popup-window/60460/2 "2022-06-07T16:51:15Z")

</div>

I would ask why these pop-ups keep getting left open - does your system open multiple popups and perhaps some are getting lost behind main windows?

Either way, I think probably the easiest catchall way to do this would be on a Client Timer script, set to run every 30 seconds. Use ([system.util.getInactivitySeconds - Ignition User Manual 8.0 - Ignition Documentation](https://docs.inductiveautomation.com/display/DOC80/system.util.getInactivitySeconds)) to see how long since the keyboard or mouse was last touch. If it’s been more than 15 seconds.

Then use [system.gui.getOpenedWindows - Ignition User Manual 8.1 - Ignition Documentation](https://docs.inductiveautomation.com/display/DOC81/system.gui.getOpenedWindows) to get all the opened windows. Assuming you have some naming convention that differentiates a popup window from a main window, such as a `Pop_` prefix or a folder where all the popups are, the psuedocode for the client event timer script would look like

You will also need [system.nav.closeWindow - Ignition User Manual 8.0 - Ignition Documentation](https://docs.inductiveautomation.com/display/DOC80/system.nav.closeWindow)

```auto
inactiveSeconds = system.util.getInactivitySeconds()
if inactiveSeconds > 15:
    for window in system.gui.getOpenedWindows():
        windowName = window.getPath()
        # some logic to determine if popup
        ispopup = ? (depends on your system)
        if ispopup:
            system.nav.closeWindow(window)

```

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [June 7, 2022, 4:57pm UTC](https://forum.inductiveautomation.com/t/timer-to-close-vision-popup-window/60460/3 "2022-06-07T16:57:12Z")

</div>

An alternative to inactivity seconds could be adding a custom property to the window that would hold the open time. Then you could use an expression binding to fire a property change event where your close the window.

```auto
secondsBetween({Root Container.openTime},now()) > 15

```

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [June 7, 2022, 5:05pm UTC](https://forum.inductiveautomation.com/t/timer-to-close-vision-popup-window/60460/4 "2022-06-07T17:05:46Z")

</div>

This was my initial idea, the only issue I have with it is I would then have to add it to every window, whereas the client timer method works with implementing it one place.

However, if your project does not have a nice naming convention or some way to tell if a window is a popup (maybe there’s some underlying java method to do this but I don’t know it off hand), then this way would be more appropriate than mine.

---

<div class="post-metadata">

**Author:** ![BRAD\_DAVIS](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/brad_davis/32/35392_2.png) [@BRAD\_DAVIS](https://forum.inductiveautomation.com/u/BRAD_DAVIS)\
**Post date:** [June 7, 2022, 5:28pm UTC](https://forum.inductiveautomation.com/t/timer-to-close-vision-popup-window/60460/5 "2022-06-07T17:28:05Z")

</div>

I do prefer the secondsBetween option.  
Is there a list of available functions and properties for stuff like the ‘Root Container’?  
Like where do you find the .openTime property even exists?

Would my end goal be an expression binding on some object on the page that does the following?:

```auto
if secondsBetween({Root Container.openTime>,now()) > 15:
	system.nav.closeWindow({Root Container})

```

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [June 7, 2022, 5:48pm UTC](https://forum.inductiveautomation.com/t/timer-to-close-vision-popup-window/60460/6 "2022-06-07T17:48:24Z")

</div>

`openTime` is a custom property that I created on the root container. Right click on the RC and select `Customizers` then `Custom Properties` (ctrl + u). Here you can add and name custom properties yourself. You can add one called `openTime` of type date, which can be added to your open popup script.

```auto
window = system.nav.openWindow('Popups/messenger', {'openTime' : system.date.now()})
system.nav.centerWindow(window)

```

You would also have another custom property on the root container that could be named `expired` of type boolean with the expression

```auto
secondsBetween({Root Container.openTime},now()) > 15

```

Then in root container’s property change event

```auto
if event.propertyName == 'expired':
	if event.newValue:
		system.nav.closeParentWindow(event)

```

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [June 7, 2022, 6:11pm UTC](https://forum.inductiveautomation.com/t/timer-to-close-vision-popup-window/60460/7 "2022-06-07T18:11:14Z")

</div>

I would probably make this

```auto
if event.propertyName == 'expired':
	if event.newValue:
		system.nav.closeParentWindow(event)

```

```auto
if event.propertyName == 'expired' and event.newValue:
	system.nav.closeParentWindow(event)

```

but that’s super minor.

However, this is what I meant regarding a lot more engineering to use this method. You have to modify

1. The system.nav.openWindow
2. Add two custom root container properties
3. Add a property change script  
multipled by however many popup containers you have (and you will probably need to do a Control+F to find all your system.nav.openWindows type scripts)

So if you have 15 popup windows you’re looking at 45 changes you have to make, versus 1 client timer script to write if you have some way to figure out by name if the window is a popup window. It is for this type of reason I highly recommend using naming conventions not only on tags, but on windows, custom properties, etc, in case you ever need extra information you want to imbue via naming.

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [June 7, 2022, 6:18pm UTC](https://forum.inductiveautomation.com/t/timer-to-close-vision-popup-window/60460/8 "2022-06-07T18:18:21Z")

</div>

I see your point, but the popup _ **I used** _ this on is in an inherited global project, so I only have a single window I needed to configure this way.

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [June 7, 2022, 6:21pm UTC](https://forum.inductiveautomation.com/t/timer-to-close-vision-popup-window/60460/9 "2022-06-07T18:21:25Z")

</div>

Also, the timer script could take up to 45 seconds to close the popup instead of 15 seconds, where the custom property will always close after _exactly_ 15 seconds

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [June 7, 2022, 6:21pm UTC](https://forum.inductiveautomation.com/t/timer-to-close-vision-popup-window/60460/10 "2022-06-07T18:21:40Z")

</div>

Oh that makes sense. I haven’t had the chance to work with projects that have inherited properties, but in that case, them yes the workload is equal and it’s just a matter of taste - would probably do your way tbh so the closing logic of the window is on the window instead of hidden away in a client timer script.

Point stands if you are using an older version of Ignition without inherited projects or don’t have an inherited popup window like that.

---

<div class="post-metadata">

**Author:** ![BRAD\_DAVIS](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/brad_davis/32/35392_2.png) [@BRAD\_DAVIS](https://forum.inductiveautomation.com/u/BRAD_DAVIS)\
**Post date:** [June 7, 2022, 6:22pm UTC](https://forum.inductiveautomation.com/t/timer-to-close-vision-popup-window/60460/11 "2022-06-07T18:22:08Z")

</div>

I get where you are both coming from with the differences between the two solutions yeah.  
I am still in the templating stage for my popup control window, the only issue i have is that i cannot make it dynamically update between the different switches being controlled as my data coming in is a DNP3 map and the tags cannot be named in a way that will allow me to completely dynamically assign the tags.

I think the solution by @dkhayes117 will work perfectly for me as once i make the template popup i will just need to copy it a handful of times and manually change a bunch of items on them anyways (unfortunately).

I would love to make the one screen dynamically update but alas that isnt possible with my tag map coming from my SCADA RTU.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [June 7, 2022, 6:25pm UTC](https://forum.inductiveautomation.com/t/timer-to-close-vision-popup-window/60460/12 "2022-06-07T18:25:12Z")

</div>

> [@dkhayes117](#):
>
> `secondsBetween({Root Container.openTime},now()) > 15`

One thing though - won't this always just trigger 15 seconds after window opens regardless of if the user is using the window or not? I think the propertyChange logic needs to incorporate inactivity.

Imagine too though we do incorporate inactivity right -

```python
if event.propertyName == 'expired' and event.newValue:
    if system.util.getInactivitySeconds() > 15:
        system.nav.closeParentWindow(event)

```

say they were active, and this doesn't go off, then the boolean value is just stuck on true, and it won't try to close the window again right? It tries once after 15 seconds, but that is it. Which I don't think is OP's intent.

Edit: Per clarification, it should be

```python
if event.propertyName == 'expired' and event.newValue:
    system.nav.closeParentWindow(event)

```

to close after 15 seconds no matte user usage.

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [June 7, 2022, 6:26pm UTC](https://forum.inductiveautomation.com/t/timer-to-close-vision-popup-window/60460/13 "2022-06-07T18:26:53Z")

</div>

Yes, that is true. If you want 15 seconds of inactivity then you would need to add that inactivity check to the script.

This throws a bit of a wrench in it as well, since after 15 seconds, that change script would fire every second after the initial 15 seconds

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [June 7, 2022, 6:28pm UTC](https://forum.inductiveautomation.com/t/timer-to-close-vision-popup-window/60460/14 "2022-06-07T18:28:43Z")

</div>

I think this would work to keep it checking every so often -

```auto
if event.propertyName == 'expired' and event.newValue:
    if system.util.getInactivitySeconds() > 15:
        system.nav.closeParentWindow(event)
    else:
        event.source.openTime = system.date.now()

```

to reset `expired` to false, and so this thing triggers again.

Though I would probably make  
the 15 in  
`system.util.getInactivitySeconds() > 15` a number less than the 15 in `secondsBetween({Root Container.openTime},now()) > 15` for better catching of inactivity.

> This throws a bit of a wrench in it as well, since after 15 seconds, that change script would fire every second after the initial 15 seconds

My impression is that changing from True to True wouldn't create another property change event.

---

<div class="post-metadata">

**Author:** ![BRAD\_DAVIS](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/brad_davis/32/35392_2.png) [@BRAD\_DAVIS](https://forum.inductiveautomation.com/u/BRAD_DAVIS)\
**Post date:** [June 7, 2022, 6:29pm UTC](https://forum.inductiveautomation.com/t/timer-to-close-vision-popup-window/60460/15 "2022-06-07T18:29:45Z")

</div>

I actually want the window to close regardless of if they are using it or not.  
This is being used for a breaker control in an Electrical Substation, so if they open the breaker control screen I don’t want them being able to leave it open.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [June 7, 2022, 6:30pm UTC](https://forum.inductiveautomation.com/t/timer-to-close-vision-popup-window/60460/16 "2022-06-07T18:30:33Z")

</div>

Disregard everything I’ve said then. Follow @dkhayes117 first recommendation.

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [June 7, 2022, 6:30pm UTC](https://forum.inductiveautomation.com/t/timer-to-close-vision-popup-window/60460/17 "2022-06-07T18:30:34Z")

</div>

> [@bkarabinchak.psi](#):
>
> My impression is that changing from True to True wouldn’t create another property change event.

Ah, yes. I missed that, good point.

---

<div class="post-metadata">

**Author:** ![BRAD\_DAVIS](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/brad_davis/32/35392_2.png) [@BRAD\_DAVIS](https://forum.inductiveautomation.com/u/BRAD_DAVIS)\
**Post date:** [June 7, 2022, 6:34pm UTC](https://forum.inductiveautomation.com/t/timer-to-close-vision-popup-window/60460/18 "2022-06-07T18:34:46Z")

</div>

No worries, I appreciate all the discussion of options though, thanks.  
I’m sure the other options will come in handy for some of the other screens i need to make for this system as well, and i have gained a much better understanding of how to use some of the backend of Ignition Scripting.

---

<div class="post-metadata">

**Author:** ![Melvin\_Miclat](https://avatars.discourse-cdn.com/v4/letter/m/ba9def/32.png) [@Melvin\_Miclat](https://forum.inductiveautomation.com/u/Melvin_Miclat)\
**Post date:** [July 15, 2024, 5:35pm UTC](https://forum.inductiveautomation.com/t/timer-to-close-vision-popup-window/60460/19 "2024-07-15T17:35:54Z")

</div>

Do we have a cleaner script for this to work. I tried to follow the scripting on this tread but i cant get it to work. Is the scripting all in the popup window? also the secondsBetween has no definition?

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [July 15, 2024, 6:05pm UTC](https://forum.inductiveautomation.com/t/timer-to-close-vision-popup-window/60460/20 "2024-07-15T18:05:43Z")

</div>

Once you create your `openTime` property, bind it to an _ **expression** _ like so `now(0)`. This way you don't have to pass it in as a parameter. When the popup opens it will automatically have the current time loaded and won't update.

`expired` would be another custom property with an _ **expression** _ binding. This is not a script, scripting language != expression language.

```python
secondsBetween({Root Container.openTime},now()) > 15

```

Then the script would come in the property change event on the component that you placed the custom properties on. _ **Then** _ you would use the script

```python
if event.propertyName == 'expired' and event.newValue:
	system.nav.closeParentWindow(event)

```

[Next page](https://forum.inductiveautomation.com/t/timer-to-close-vision-popup-window/60460.md?page=2)
