So basically I want to run a few line of code each time a specific application is launched and closed.
Is there application which could do that ? (Busybox ?)
I actually have to print it my self in a terminal emulator and it's a bit harsh :/
Using Terminal Emulator and Macrodroid, an automation app
Create a macro in which the Trigger is launch application of your choice and action is Launch Shortcut where you choose Term Shortcut and key in the commands in the arguments . See Firelord's answer here for additional details Home screen icon for terminal program?
To understand how MacroDroid works and required settings, my answer here
See this to enter multiple commands Run 2 commands in the same line in terminal emulator ( since you mentioned you have a few lines of code not a single command )
su
(application block when I want to add other lines, any advice ?)
su-c
Commented
Sep 29, 2016 at 10:36
&&
to join command unless the first command is executed the next will not run. Breaking into sections and multiple actions can help troubleshoot
Commented
Sep 29, 2016 at 10:43