# Get current scope in scripting

**URL:** <https://forum.inductiveautomation.com/t/get-current-scope-in-scripting/55686>\
**Category:** General Discussion\
**Created:** [February 2, 2022, 9:35pm UTC](https://forum.inductiveautomation.com/t/get-current-scope-in-scripting/55686 "2022-02-02T21:35:03Z")\
**Posts on this page:** 1\
**Showing post:** 18

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [May 8, 2025, 1:49am UTC](https://forum.inductiveautomation.com/t/get-current-scope-in-scripting/55686/18 "2025-05-08T01:49:06Z")

</div>

There are a number of topics about this, with this being the only topic that works to distinguish between gateway and perspective 🙂 thanks @paul-griffith and @hunterdg

I've incorporated this into @Kyle_Chase 's script from [this topic](https://forum.inductiveautomation.com/t/best-methods-for-checking-script-scope/30201/2):

```python
from com.inductiveautomation.ignition.common.model import ApplicationScope
try:
	from com.inductiveautomation.ignition.gateway import IgnitionGateway
	isGateway = True
except ImportError:
	isGateway = False

def getScope():
	scope = ApplicationScope.getGlobalScope()
	
	if ApplicationScope.isClient(scope):
		return "vision"

	elif ApplicationScope.isDesigner(scope):
		return "designer"

	elif ApplicationScope.isGateway(scope):
		pageModel = IgnitionGateway.get().moduleManager.resolveClass("com.inductiveautomation.perspective.gateway.model.PageModel")
		if pageModel.PAGE.get() is not None:
			return "perspective"
		return "gateway"
	
	else:
		raise ValueError("Could not resolve execution scope!")

```

Edit:  
This is simpler from [Can I tell what scope a script is running from? - #9 by Michael\_Lindon](https://forum.inductiveautomation.com/t/can-i-tell-what-scope-a-script-is-running-from/70880/9)

```python
def getScope():
	scope = ApplicationScope.getGlobalScope()
	if ApplicationScope.isClient(scope):
		return "c" # vision client

	if ApplicationScope.isDesigner(scope):
		return "d" # designer

	if ApplicationScope.isGateway(scope):
		try:
			system.perspective.getProjectInfo()
			return "p"
		except:
			return "g"
	return "u" # unknown

```

---

_[View the full topic](https://forum.inductiveautomation.com/t/get-current-scope-in-scripting/55686)._
