This post came up in a lot in my searches and had to make adjustments to it to differentiate between whether a script was being run on the Gateway vs a Perspective Session Scope, IE whether Perspective session properties exist. Here is a quick change to the above method that solved it for me.
from com.inductiveautomation.ignition.common.model import ApplicationScope
class Scope(object):
@staticmethod
def get():
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