Every script does two things: send a command, wait_for the response.
# Wait for the command prompt, then send a command
wait_for("Command [TL=00:00:00]:[1]?")
send("I")
# Wait for the info menu, then go back
wait_for("Information")
send("Q")
The wait_for looks at what the game actually sent. The send types your command. That's it. Everything else is just repeating this pattern.
Your script sees what you see. Learn the prompts:
Command [TL=00:00:00]:[1]? — the main prompt. You're at a sector.(?) Help — help menu is open.Commerce report — you just docked at a port.Match on the exact text. If the game says "Command" and you wait for "command" (lowercase), it won't match. Case matters.