The development of Wireless Sensor Networks (WSNs) applications is an arduous task, since the developer has to design the behavior of the nodes and their interactions. The automatic generation of WSN's applications is desirable to reduce costs, since it drastically reduces the human effort. This paper presents the use of Genetic Programming to automatically generate WSNs applications. A scripting language based on events and actions is proposed to represent the WSN behavior. Events represent the state of a given sensor node and actions modify these states. Some events are internal states and others are external states captured by the sensors. A parallel genetic algorithm is used to automatically generate WSNs applications in this scripting language. These scripts are executed by a middleware installed on all sensors nodes. This approach enables the application designer to define only the overall objective of the WSN. This objective is defined by means of a fitness function. An event-detection problem is presented in order to evaluate the proposed method. The results showed the capability of the developed approach to successfully solve WSNs problems through the automatic generation of applications.