# OpenHAB python script run after button press

Date: 2017-09-15

A short tutorial on how to run a python script in response to a button press.

[Last post](http://goldmanmalka.com/2017/09/13/openhab-gpio-button/) I add a GPIO button to the OpenHAB pi

<!--more-->

Today I wanted to add the ability to run a Python script in reaction to that press.

  * Important note: the script needs to be owned by the user openhab to be able to run

/etc/openhab2/items/btn.items -
```shell
Contact NormallyOpenPushButton "Normally Open Push Button [%s]" { gpio="pin:4 debounce:10000" }
```

/etc/openhab2/rules/btn.rules -

```shell
rule "btn pressed"
when
    Item NormallyOpenPushButton changed
then
    val results = executeCommandLine("/tmp/d/dd", 5000)
    logInfo("execTest", results)
end
```

/tmp/d/dd -

```shell
#!/bin/bash
echo "$(date)" &gt;&gt; /tmp/d/tmp.txt
```

don't forget to change the owner of both dd and tmp.txt

```shell
chown openhab:openhab dd
chown openhab:openhabtmp.txt
```

Refrenseto the article that helped me solve the permission issue: <https://community.openhab.org/t/how-to-solve-exec-binding-problems/18131>
