# How to trigger script written in project library

**URL:** <https://forum.inductiveautomation.com/t/how-to-trigger-script-written-in-project-library/61002>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [June 21, 2022, 12:50pm UTC](https://forum.inductiveautomation.com/t/how-to-trigger-script-written-in-project-library/61002 "2022-06-21T12:50:26Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![gunpathe](https://avatars.discourse-cdn.com/v4/letter/g/8e7dd6/32.png) [@gunpathe](https://forum.inductiveautomation.com/u/gunpathe)\
**Post date:** [June 21, 2022, 12:50pm UTC](https://forum.inductiveautomation.com/t/how-to-trigger-script-written-in-project-library/61002/1 "2022-06-21T12:50:27Z")

</div>

I have created a simple gateway event script for testing.

```auto
def test:
      a =1
      b=2
      c = a+b
      print c

test()

```

And i have named this script as **Test**  
After saving the script, i have waited for this to execute automatically but didnt work.

if i run the same script in script console, it is working… I believe there is nothing wrong with this test script.

I just wanna run this Test script automatically, Anyone pls tell me how to do that?

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 21, 2022, 12:52pm UTC](https://forum.inductiveautomation.com/t/how-to-trigger-script-written-in-project-library/61002/2 "2022-06-21T12:52:33Z")

</div>

When you create a gateway event script you have to choose what event is to trigger it. Your options are:

- Startup
- Update
- Shutdown
- Timer
- Tag Change
- Message
- Scheduled

Which did you choose and what was the trigger?

---

<div class="post-metadata">

**Author:** ![gunpathe](https://avatars.discourse-cdn.com/v4/letter/g/8e7dd6/32.png) [@gunpathe](https://forum.inductiveautomation.com/u/gunpathe)\
**Post date:** [June 21, 2022, 12:55pm UTC](https://forum.inductiveautomation.com/t/how-to-trigger-script-written-in-project-library/61002/3 "2022-06-21T12:55:05Z")

</div>

okay,  
I have created the Test script under the Scripting section,

Could you pls tell me to run that script?

---

<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:** [June 21, 2022, 12:56pm UTC](https://forum.inductiveautomation.com/t/how-to-trigger-script-written-in-project-library/61002/4 "2022-06-21T12:56:10Z")

</div>

That’s a library script, not an event script. Library scripts don’t run unless an event calls a function within them. One of the events @Transistor listed.

Edit: Also note that when you have an event that calls `Test.test()`, the first time will yield **two** calls to `test()`, since you include a call at the top level of the library script. The top level runs once, to completion, the first time any member of it is accessed. (Like an auto-import.)

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [June 21, 2022, 12:56pm UTC](https://forum.inductiveautomation.com/t/how-to-trigger-script-written-in-project-library/61002/5 "2022-06-21T12:56:20Z")

</div>

Another thing to note here is that `print 'hi'` in the gateway context - you will never see this.

You need to use a logger to log your messages to the gateway.

```auto
def test():
    logger = system.util.getLogger("My Logger")
    a=1
    b=2
    c = a + b
    logger.info("Value of c is %i"%(c))

```

is how you would be able to see results in your gateway logs.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 21, 2022, 1:01pm UTC](https://forum.inductiveautomation.com/t/how-to-trigger-script-written-in-project-library/61002/6 "2022-06-21T13:01:32Z")

</div>

> [@gunpathe](#):
>
> I have created the Test script under the Scripting section

You need to be more precise in your writing. Your question title says "event script". I now suspect that you mean you have written it in the Project Library.

You can run a Project Library script from a button.

- Right-click the button.
- Select _Configure Events ..._.
- Select _onActionPerformed_, hit + and select _Script_.
- Add the path and name of script.

---

<div class="post-metadata">

**Author:** ![gunpathe](https://avatars.discourse-cdn.com/v4/letter/g/8e7dd6/32.png) [@gunpathe](https://forum.inductiveautomation.com/u/gunpathe)\
**Post date:** [June 21, 2022, 1:04pm UTC](https://forum.inductiveautomation.com/t/how-to-trigger-script-written-in-project-library/61002/7 "2022-06-21T13:04:54Z")

</div>

Thanks,  
I was doing it in multiple ways, forgot to rename it.

---

<div class="post-metadata">

**Author:** ![Salien](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Salien](https://forum.inductiveautomation.com/u/Salien)\
**Post date:** [October 3, 2024, 12:43am UTC](https://forum.inductiveautomation.com/t/how-to-trigger-script-written-in-project-library/61002/8 "2024-10-03T00:43:21Z")

</div>

If anyone else forgot like me - syntax of the path and name of the script is not as the project browser "copy path" feature gives - need to change slashes for dots.  
So not `Folder/Subfolder/Library_Script.method(args)` but `Folder.Subfolder.Library_Script.method(args)`

Edit: Project browser tree copy path. Didn't know there was a similar tool in the script editor!

---

<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:** [October 3, 2024, 2:18am UTC](https://forum.inductiveautomation.com/t/how-to-trigger-script-written-in-project-library/61002/9 "2024-10-03T02:18:03Z")

</div>

In new-ish versions of Ignition, the auto complete (Ctrl+space) will provide you paths to your project library functions.

---

<div class="post-metadata">

**Author:** ![Salien](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@Salien](https://forum.inductiveautomation.com/u/Salien)\
**Post date:** [October 3, 2024, 3:08am UTC](https://forum.inductiveautomation.com/t/how-to-trigger-script-written-in-project-library/61002/10 "2024-10-03T03:08:08Z")

</div>

Thanks, yeah. Even without ctrl+space, 8.1 does propose completions if you start typing but if you paste an invalid path after copying one then it it does not.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [October 3, 2024, 8:04am UTC](https://forum.inductiveautomation.com/t/how-to-trigger-script-written-in-project-library/61002/11 "2024-10-03T08:04:47Z")

</div>

> [@Salien](#):
>
> syntax of the path and name of the script is not as the "copy path" feature gives - need to change slashes for dots.

What ? Where are you copying it from ?  
Mine gives the proper path:

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/9/899cb05a7a58a1fb75bc58e308d4159cae2154b6.png)

> `lib.dict.sanitize_keys(dic, sfunc=make_key, recursive=True)`

---

<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:** [October 3, 2024, 1:06pm UTC](https://forum.inductiveautomation.com/t/how-to-trigger-script-written-in-project-library/61002/12 "2024-10-03T13:06:07Z")

</div>

Probably from the project browser menu. I can see how that would be confusing.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [October 3, 2024, 1:32pm UTC](https://forum.inductiveautomation.com/t/how-to-trigger-script-written-in-project-library/61002/13 "2024-10-03T13:32:36Z")

</div>

Right, didn't even notice you could get a path from there. Not sure what it would be useful for though ?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [October 3, 2024, 1:34pm UTC](https://forum.inductiveautomation.com/t/how-to-trigger-script-written-in-project-library/61002/14 "2024-10-03T13:34:40Z")

</div>

Mostly useful for Vision windows, but probably a generic action added to an abstract tree node class, so everything gets it.
