# system.print.getDefaultPrinterName() not working

**URL:** <https://forum.inductiveautomation.com/t/system-print-getdefaultprintername-not-working/82729>\
**Category:** Ignition\
**Tags:** perspective, scripting\
**Created:** [December 5, 2023, 4:52pm UTC](https://forum.inductiveautomation.com/t/system-print-getdefaultprintername-not-working/82729 "2023-12-05T16:52:23Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gratliff](https://avatars.discourse-cdn.com/v4/letter/g/a5b964/32.png) [@Gratliff](https://forum.inductiveautomation.com/u/Gratliff)\
**Post date:** [December 5, 2023, 4:52pm UTC](https://forum.inductiveautomation.com/t/system-print-getdefaultprintername-not-working/82729/1 "2023-12-05T16:52:23Z")

</div>

I'm trying to print labels to a Zebra printer connected to a laptop running a Perspective session. I want to view the connected printers and the default printer on that laptop. When my script runs, it returns null. There are no printers configured on this gateway. If I run the script in the script console, it returns the printer(s) from my computer.  
Shouldn't this function return printers from the local machine running the session, not the gateway? Am I missing something obvious?

```
defaultPrinter = system.print.getDefaultPrinterName()

self.view.custom.defaultPrinter = defaultPrinter

```

I should also point out that system.print.getPrinterNames() also returns null from my script within the session.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 5, 2023, 4:55pm UTC](https://forum.inductiveautomation.com/t/system-print-getdefaultprintername-not-working/82729/2 "2023-12-05T16:55:28Z")

</div>

> [@Gratliff](#):
>
> Am I missing something obvious?

Unfortunately, yes.

Perspective scripts are being run on the gateway, because web browsers don't know how to run Python or Jython, only Javascript. So your script is never going to be run on the local machine.

Even if you could run your code directly on the local user agent, you _cannot_ access information like "what printers are on the local machine" (not even from Javascript), because it's a privacy nightmare that would be abused by every adtech business under the sun.

---

<div class="post-metadata">

**Author:** ![Gratliff](https://avatars.discourse-cdn.com/v4/letter/g/a5b964/32.png) [@Gratliff](https://forum.inductiveautomation.com/u/Gratliff)\
**Post date:** [December 5, 2023, 4:57pm UTC](https://forum.inductiveautomation.com/t/system-print-getdefaultprintername-not-working/82729/3 "2023-12-05T16:57:33Z")

</div>

Thanks for the quick response.

Just so I understand fully, the documentation reads "Obtains the local default printer." When it says local, it's referring to a printer local to the gateway, correct?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 5, 2023, 5:00pm UTC](https://forum.inductiveautomation.com/t/system-print-getdefaultprintername-not-working/82729/4 "2023-12-05T17:00:08Z")

</div>

"Local" to whatever execution scope is running the script. If you call it from the gateway (via tag event script, SFC, alarm pipeline, scheduled report, or Perspective session) - it's going to give you whatever the OS reports as the default printer name _to the Gateway_. If you're executing your code in the client or designer (in the script console or a Vision window), it's going to give you whatever the OS reports as the default printer name to that local executable; Vision/the Designer have tigher integration with the local system than is possible with Perspective.

---

<div class="post-metadata">

**Author:** ![Gratliff](https://avatars.discourse-cdn.com/v4/letter/g/a5b964/32.png) [@Gratliff](https://forum.inductiveautomation.com/u/Gratliff)\
**Post date:** [December 6, 2023, 9:45pm UTC](https://forum.inductiveautomation.com/t/system-print-getdefaultprintername-not-working/82729/5 "2023-12-06T21:45:02Z")

</div>

So, we added a network printer to the gateway (set as default), and we get either an empty list from system.print.getPrinterNames(), or we get null back from system.print.getDefaultPrinterName(). There is also the standard "Microsoft XPS Document Writer" driver installed on the gateway. I would expect that to show up in the list of printer names as well.  
Is there any further advice you can provide to assist troubleshooting this considering these changes?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 6, 2023, 9:50pm UTC](https://forum.inductiveautomation.com/t/system-print-getdefaultprintername-not-working/82729/6 "2023-12-06T21:50:06Z")

</div>

> [@Gratliff](#):
>
> gateway (set as default)

Windows printer name lists and default printer status is per-user. The gateway runs as a **service** in the background, typically under a system account that doesn't have most network privileges. Logging into the server's desktop as a regular user and adjusting pretty much any settings **has no effect on the service**.

You should get your IT group to provide a suitably-configured user account for the background service.

---

<div class="post-metadata">

**Author:** ![Gratliff](https://avatars.discourse-cdn.com/v4/letter/g/a5b964/32.png) [@Gratliff](https://forum.inductiveautomation.com/u/Gratliff)\
**Post date:** [December 6, 2023, 9:52pm UTC](https://forum.inductiveautomation.com/t/system-print-getdefaultprintername-not-working/82729/7 "2023-12-06T21:52:18Z")

</div>

Thanks! When I had them set up the printer but failed to mention that the service is what will access it.  
I appreciate the quick answer!

---

<div class="post-metadata">

**Author:** ![Francisco\_Ochoa](https://avatars.discourse-cdn.com/v4/letter/f/e495f1/32.png) [@Francisco\_Ochoa](https://forum.inductiveautomation.com/u/Francisco_Ochoa)\
**Post date:** [September 30, 2024, 10:00pm UTC](https://forum.inductiveautomation.com/t/system-print-getdefaultprintername-not-working/82729/8 "2024-09-30T22:00:00Z")

</div>

how do you change the default from gateway?

---

<div class="post-metadata">

**Author:** ![michael.flagler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/michael.flagler/32/26272_2.png) [@michael.flagler](https://forum.inductiveautomation.com/u/michael.flagler)\
**Post date:** [September 30, 2024, 10:02pm UTC](https://forum.inductiveautomation.com/t/system-print-getdefaultprintername-not-working/82729/9 "2024-09-30T22:02:35Z")

</div>

To change the default on the gateway, you'll need to make sure the Ignition service is running under a user and not SYSTEM (assuming Windows), then login with that same username on the gateway and set the default printer appropriately.
