Hi, thanks for your script

I want to ask for help about writing a script that achieves the following function:
1. Open the last opened book.
2. turn on bluetooth
3. pairing the headphone
4. entering tts mode and start to play
I have CS program but have little experience writing scripts in Linux environment. I am wondering if there is any documentation for this or if you could tell me how you find these api for toggling the interface of the pocketbook.