# Where do/should Gateway Scripts live with respect to an inherited project structure?

**URL:** <https://forum.inductiveautomation.com/t/where-do-should-gateway-scripts-live-with-respect-to-an-inherited-project-structure/83460>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [December 22, 2023, 4:39am UTC](https://forum.inductiveautomation.com/t/where-do-should-gateway-scripts-live-with-respect-to-an-inherited-project-structure/83460 "2023-12-22T04:39:57Z")\
**Posts on this page:** 1\
**Showing post:** 14

<div class="post-metadata">

**Author:** ![sherman](https://avatars.discourse-cdn.com/v4/letter/s/e5b9ba/32.png) [@sherman](https://forum.inductiveautomation.com/u/sherman)\
**Post date:** [December 27, 2023, 11:12pm UTC](https://forum.inductiveautomation.com/t/where-do-should-gateway-scripts-live-with-respect-to-an-inherited-project-structure/83460/14 "2023-12-27T23:12:34Z")

</div>

Okay -- its kind of working actually. I can call methods that would actually not work when called from the script console:

```auto
#MyScripts in 'base_script' inherited by 'dev'
import os
def local_ls(path):
	return os.listdir(path)

def invokeGateway(callback, *args, **kwargs):
	return system.util.sendRequest("dev", "runScript", 
		{"callback": callback, "args": args, "kwargs": kwargs})

```

```auto
# script console in project base_script (should be agnostic to project?)
payload = {"callback": "MyScripts.local_ls", "args": ["/"]}
system.util.sendRequest("dev", "runScript", payload)

```

```auto
# Gateway message script 'runScript' in project "dev" 
# which is a grandchild of base_script
def handleMessage(payload):
	try:
		callback = payload['callback']
		args = payload.get('args', [])
		kwargs = payload.get('kwargs', {})
		cb_parts = callback.split('.')
		tgt = globals()
		for i in range(len(cb_parts)):
			if i == 0:
				#the handling for globals() doesn't support hasattr apparently
				tgt = tgt[cb_parts[i]] 
			elif not hasattr(tgt, cb_parts[i]):
				e = {"error": "missing {} from {}".format(cb_parts[i], str(tgt))}
				return e
			tgt = getattr(tgt, cb_parts[i])
		result = tgt(*args, **kwargs)
		return result
	except Exception as e:
		return {"error": str(e)}

```

It actually works finally!

---

_[View the full topic](https://forum.inductiveautomation.com/t/where-do-should-gateway-scripts-live-with-respect-to-an-inherited-project-structure/83460)._
