Use an application automatically
There is app called automate which probably achieve what ur saying like following examples like 


sending message on specific app is running, when like battery percent is n% then do this, etc. 


More description on there website