# system.gui.openDesktop() fails occasionally

**URL:** <https://forum.inductiveautomation.com/t/system-gui-opendesktop-fails-occasionally/73647>\
**Category:** Ignition\
**Tags:** ignition81, vision\
**Created:** [May 12, 2023, 1:00pm UTC](https://forum.inductiveautomation.com/t/system-gui-opendesktop-fails-occasionally/73647 "2023-05-12T13:00:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Francesco\_Terraneo1](https://avatars.discourse-cdn.com/v4/letter/f/65b543/32.png) [@Francesco\_Terraneo1](https://forum.inductiveautomation.com/u/Francesco_Terraneo1)\
**Post date:** [May 12, 2023, 1:00pm UTC](https://forum.inductiveautomation.com/t/system-gui-opendesktop-fails-occasionally/73647/1 "2023-05-12T13:00:40Z")

</div>

Hi there,

I'm using the function system.gui.openDesktop() to manage a multi screen application.  
Occasionally the desktop opening fails, without any log.

code:

```auto
		for d in range(0,dn):
		
			frame= system.gui.openDesktop(windows=['myWindow'], title='Desk ' + str(d), handle=str(d), x=1920*d, y=0, width=1920, height=1080)

```

The fail is random, on desk 0, 1 or both. most of the time it works, but it is annoying and I'm wondering if I'm making any mistake.

Any suggestion?

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [May 12, 2023, 11:54pm UTC](https://forum.inductiveautomation.com/t/system-gui-opendesktop-fails-occasionally/73647/2 "2023-05-12T23:54:12Z")

</div>

> [@Francesco\_Terraneo1](#):
>
> `for d in range(0,dn):`

What determines `dn`?

> [@Francesco\_Terraneo1](#):
>
> `x=1920*d`

Any chance they are opening off screen?

> [@Francesco\_Terraneo1](#):
>
> `frame=`

Why is `system.gui.openDesktop` being assigned to this variable? Are we doing something with this afterwards that could be causing an issue?

---

<div class="post-metadata">

**Author:** ![Francesco\_Terraneo1](https://avatars.discourse-cdn.com/v4/letter/f/65b543/32.png) [@Francesco\_Terraneo1](https://forum.inductiveautomation.com/u/Francesco_Terraneo1)\
**Post date:** [May 15, 2023, 4:07pm UTC](https://forum.inductiveautomation.com/t/system-gui-opendesktop-fails-occasionally/73647/3 "2023-05-15T16:07:07Z")

</div>

Hi Justin,  
dn is how many desktop to open, in my case is set to 2 so desk 0 and 1 will open.  
no, the resolution is correct.

`system.gui.openDesktop` is assigned to frame var, on next row:

```auto
frame.setAlwaysOnTop(True)

```

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [June 4, 2023, 2:14am UTC](https://forum.inductiveautomation.com/t/system-gui-opendesktop-fails-occasionally/73647/4 "2023-06-04T02:14:12Z")

</div>

My apologies for the late response, I got sidetracked with other things and forgot to follow up on this.

I do a lot of multidesktop scripting, and I've never had any problems, so naturally, I look for things that are being done differently. For example, I only ever specify x and y on really large monitors or when opening multiple desktops in the same screen. Even so, I've never seen the script fail because of a coordinate specification. One thing that I've never done is assign the openDesktop to a variable and setAlwaysOnTop, but this should be doable with a JFrame, so I don't understand why that would be a problem.

One thing we haven't explored is where is this script being called from? Perhaps that could be the issue.

In any case, here is an example of using the screen data to set the desktops instead of directly specifying the coordinates. Try this and see if the problem persists:

```auto
openDesktops = len(system.gui.getDesktopHandles())
monitorData = system.gui.getScreens()
if openDesktops == 0 and len(monitorData) > 1:
	for desktopIndex, desktopWidth, desktopHeight in monitorData[1:]:
		handleName = "Desktop %d" %desktopIndex
		system.gui.openDesktop(screen=desktopIndex, handle=handleName, width=desktopWidth, height=desktopHeight).setAlwaysOnTop(True)
		#system.nav.desktop(handleName).swapTo('whatever/window/path')
elif openDesktops > 0:
	print 'Execution halted: Multiple open desktops have been detected'
else:
	print 'Execution halted: Only one monitor detected'

```

---

<div class="post-metadata">

**Author:** ![Francesco\_Terraneo1](https://avatars.discourse-cdn.com/v4/letter/f/65b543/32.png) [@Francesco\_Terraneo1](https://forum.inductiveautomation.com/u/Francesco_Terraneo1)\
**Post date:** [June 5, 2023, 6:31am UTC](https://forum.inductiveautomation.com/t/system-gui-opendesktop-fails-occasionally/73647/5 "2023-06-05T06:31:40Z")

</div>

Thank you for the reply,  
the script is called in the client startup script, I'll try your method and I'll came back to you.

---

<div class="post-metadata">

**Author:** ![amarks](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/amarks/32/45610_2.png) [@amarks](https://forum.inductiveautomation.com/u/amarks)\
**Post date:** [March 1, 2024, 8:44pm UTC](https://forum.inductiveautomation.com/t/system-gui-opendesktop-fails-occasionally/73647/6 "2024-03-01T20:44:25Z")

</div>

I have 3 monitors. 0 is in the center, 1 is on the left, 2 is on the right.

Using your script on a button on monitor 0, I get 2 new desktops but they're on monitors 0 and 1, respectively. I tried changing it to `screen=desktopIndex+1`, but then I just get a new desktop on screen 1. I can't get one to open on screen 2, and they don't open full-screen at the 0,0 position.

Here's the result of the getScreens() and getDesktopHandles() functions:

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/f/2f123e19ad602099d20e5cc02fba0626502bdfd1.png)

My desktop window on monitor 1 is also too large (extends on to monitor 0).
