# Reference a Gateway script name within the script

**URL:** <https://forum.inductiveautomation.com/t/reference-a-gateway-script-name-within-the-script/22402>\
**Category:** General Discussion\
**Tags:** scripting\
**Created:** [February 6, 2019, 10:10pm UTC](https://forum.inductiveautomation.com/t/reference-a-gateway-script-name-within-the-script/22402 "2019-02-06T22:10:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jsteward](https://avatars.discourse-cdn.com/v4/letter/j/8e7dd6/32.png) [@jsteward](https://forum.inductiveautomation.com/u/jsteward)\
**Post date:** [February 6, 2019, 10:10pm UTC](https://forum.inductiveautomation.com/t/reference-a-gateway-script-name-within-the-script/22402/1 "2019-02-06T22:10:36Z")

</div>

This is probably very simple, but I could not find any reference to it in the forums. I have a gateway script running and would like to create a logger for the script based on the gateway script name. Instead of hard coding the script name, can I get the name from some property?

any help is appreciated.  
Thanks

---

<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:** [February 6, 2019, 10:13pm UTC](https://forum.inductiveautomation.com/t/reference-a-gateway-script-name-within-the-script/22402/2 "2019-02-06T22:13:26Z")

</div>

The builtin ` __name__ ` should work; you can also try logging the result of `dir()` (you may need to wrap it as a string) to introspect the namespace available for your script at execution time.

---

<div class="post-metadata">

**Author:** ![jsteward](https://avatars.discourse-cdn.com/v4/letter/j/8e7dd6/32.png) [@jsteward](https://forum.inductiveautomation.com/u/jsteward)\
**Post date:** [February 7, 2019, 12:28am UTC](https://forum.inductiveautomation.com/t/reference-a-gateway-script-name-within-the-script/22402/3 "2019-02-07T00:28:50Z")

</div>

Thanks for the reply, the **name** variable did not give me the name of the script. It just gave me “main”. Also, not sure what to do with the dir() command.

---

<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:** [February 7, 2019, 12:45pm UTC](https://forum.inductiveautomation.com/t/reference-a-gateway-script-name-within-the-script/22402/4 "2019-02-07T12:45:40Z")

</div>

The ` __name__ ` variable will only be valid at the top level of a script module, not an event script. The dir() function yields a list of names in scope in which it is called, or if given an object, the list of property names for that object. You can convert that list to a string and log it, reviewing the result in your gateway log.

---

<div class="post-metadata">

**Author:** ![10mail](https://avatars.discourse-cdn.com/v4/letter/1/7bcc69/32.png) [@10mail](https://forum.inductiveautomation.com/u/10mail)\
**Post date:** [February 15, 2019, 3:58pm UTC](https://forum.inductiveautomation.com/t/reference-a-gateway-script-name-within-the-script/22402/5 "2019-02-15T15:58:29Z")

</div>

Can you import/export that list somehow, by the way?
