API to get current working appID

I have a script to do some automation for users, everything works fine until users start to open up a second Natron instance. I realized that was because I am using app1 for the script, which means if users open a new Natron with File-> New Project, the new Natron Instance became app2, scripts run on new instance will still executed on app1, the first opened Natron instance. This only happens if you start a new instance with File → New Project on menubar.
I’ve tried getAppID(), and getGuiInstance() but these all seems to required knowing current app object id. Is there any recommendation to get current working appID based on where the script is executed?

what about app?

What do you mean? Does app means current working AppID?
From reading API document, under App section, I thought that Natron only does this in background mode. I am working in GUI mode, if I call app without assigning it, I will get the following, NameError: name 'app' is not defined.
The most interesting thing to me is that Natron appID only increase if you open a new Natron under File Menu, New Project or Open Project. If you simply execute natron binary again you will still get app1 which makes scripts use app1 works fine on all instance except the one open within Natron GUI.

app should be defined in expressions, PyPlugs, and “toolsets” (such as SplitAndJoin.py)
how do you execute your script from the GUI?

in PyPlugs and toolsets, app is passed as a parameter to createInstance().
In expressions, app is always defined to be the current app object.

For now, I executed script from script editor directly. I am planning to add script to initGUI.py once the script is done.

Hey, just make another test, app works just fine in initGUI.py
This issue only happens in script editor, I guess I will add app = app1 for tesing in script editor, and remove it before I put it into initGUI.py