# Script to press a button

**URL:** <https://forum.inductiveautomation.com/t/script-to-press-a-button/78347>\
**Category:** Ignition\
**Tags:** ignition79, scripting\
**Created:** [August 24, 2023, 5:28pm UTC](https://forum.inductiveautomation.com/t/script-to-press-a-button/78347 "2023-08-24T17:28:41Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![sathianandan.dharmas](https://avatars.discourse-cdn.com/v4/letter/s/53a042/32.png) [@sathianandan.dharmas](https://forum.inductiveautomation.com/u/sathianandan.dharmas)\
**Post date:** [August 24, 2023, 5:28pm UTC](https://forum.inductiveautomation.com/t/script-to-press-a-button/78347/1 "2023-08-24T17:28:41Z")

</div>

I want to run a script instead of pressing a button and get the same results as the actionPerformed event on the button. Basically, virtually pressing a button using a script.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [August 24, 2023, 5:29pm UTC](https://forum.inductiveautomation.com/t/script-to-press-a-button/78347/2 "2023-08-24T17:29:55Z")

</div>

Put the logic into a project script. Then you can call it from anywhere (within the project).

---

<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:** [August 24, 2023, 5:30pm UTC](https://forum.inductiveautomation.com/t/script-to-press-a-button/78347/3 "2023-08-24T17:30:18Z")

</div>

What’s the trigger, and why do you think you need to press a button to activate the script ?

---

<div class="post-metadata">

**Author:** ![sathianandan.dharmas](https://avatars.discourse-cdn.com/v4/letter/s/53a042/32.png) [@sathianandan.dharmas](https://forum.inductiveautomation.com/u/sathianandan.dharmas)\
**Post date:** [August 24, 2023, 5:31pm UTC](https://forum.inductiveautomation.com/t/script-to-press-a-button/78347/4 "2023-08-24T17:31:17Z")

</div>

But the logic uses properties from other components on a template so I would have to pass a bunch of parameters to the project script and back

---

<div class="post-metadata">

**Author:** ![sathianandan.dharmas](https://avatars.discourse-cdn.com/v4/letter/s/53a042/32.png) [@sathianandan.dharmas](https://forum.inductiveautomation.com/u/sathianandan.dharmas)\
**Post date:** [August 24, 2023, 5:33pm UTC](https://forum.inductiveautomation.com/t/script-to-press-a-button/78347/5 "2023-08-24T17:33:56Z")

</div>

The trigger is a simple 'if' condition in a script on the same template as the button. So when this if condition is met I want to execute the "action performed" script of the button. It's a really long script that's why I didn't want to copy paste it and just "click" the button instead.

---

<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:** [August 24, 2023, 5:34pm UTC](https://forum.inductiveautomation.com/t/script-to-press-a-button/78347/6 "2023-08-24T17:34:11Z")

</div>

That’s still the appropriate way of doing this.  
Also, I’m sure you could reduce the number of parameters to pass by pre-processing things and storing the results in properties

Though I just saw you’re on 7.9, and there might be different ways of doing things in vision

---

<div class="post-metadata">

**Author:** ![sathianandan.dharmas](https://avatars.discourse-cdn.com/v4/letter/s/53a042/32.png) [@sathianandan.dharmas](https://forum.inductiveautomation.com/u/sathianandan.dharmas)\
**Post date:** [August 24, 2023, 5:35pm UTC](https://forum.inductiveautomation.com/t/script-to-press-a-button/78347/7 "2023-08-24T17:35:31Z")

</div>

Gotcha, thanks! I remember doing this before, where I was able to virtually press the button but I can't seem to find it on my current project.

Thanks for helping though

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [August 24, 2023, 5:38pm UTC](https://forum.inductiveautomation.com/t/script-to-press-a-button/78347/8 "2023-08-24T17:38:30Z")

</div>

> [@Trigger a button Click with text entry](https://forum.inductiveautomation.com/t/trigger-a-button-click-with-text-entry/37507/10):
>
> Try this, Jython is a structured language so white space matters. Where many languages have brackets to determine scope, Python/Jython uses white space for this. Use two spaces for indention or a tab if event.propertyName == 'text': button = event.source.parent.getComponent('button 2') button.doClick()

---

<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:** [August 24, 2023, 5:42pm UTC](https://forum.inductiveautomation.com/t/script-to-press-a-button/78347/9 "2023-08-24T17:42:47Z")

</div>

I would recommend learning from this experience. I write all my business logic in project scripts as much as possible first and recommend that to my newer ignition coworkers, and then _call_ them from the GUI or tag change events or what have you. The GUI should only be there to let users pick parameters for these functions. Then this sort of situation would be very easy to manage.

---

<div class="post-metadata">

**Author:** ![sathianandan.dharmas](https://avatars.discourse-cdn.com/v4/letter/s/53a042/32.png) [@sathianandan.dharmas](https://forum.inductiveautomation.com/u/sathianandan.dharmas)\
**Post date:** [August 24, 2023, 5:50pm UTC](https://forum.inductiveautomation.com/t/script-to-press-a-button/78347/10 "2023-08-24T17:50:32Z")

</div>

@JordanCClark That's exactly what I was looking for doClick().

Thanks a lot for the quick response!!
